Postman has many built in Javascript libraries. Postman Moment is one of the more useful ones for getting dates such as today’s date or tomorrow’s.
Creating a Date with Moment
Moment is another tool build into postman that can be used for your test. This is great for creating a rolling future, current or past date. You can add and subtract time be it minutes, hours, days, months, or years. You can also change the format to match what you need.
var moment = require('moment');
var date = moment().add(10, 'days').format('MM/DD/YYYY');
var date2 = moment().add(1, 'month').format('MM/DD/YYYY');
pm.environment.set("date", date);More Testing with Postman
- Testing with Postman: Getting Started
- Testing with Postman: Variables
- Testing with Postman: Reusable Code
- Testing with Postman: Headers
- Testing with Postman: Looping Test
- Testing with Postman: Chai Assertions
- Testing with Postman: Lodash
- Testing with Postman: Checking Schema
- Testing with Postman: Newman for CI/CD
- Testing with Postman: A Complete Guide to Automation
Links
Postman Quick Reference Guide
Chai Assertion Library
Regex Cheat Sheet
Postman: The Complete Guide on Udemy
