How to use date and timestamp in postman

Many times we need to pass timestamp or date as request parameter. One way is to use predefined variable like {{$timestamp}}. But this can not be used when it’s needed in specific format. So to achieve that we should use ‘Pre-Request Script’ option. Use below code in pre request script. Here we are using moment class to get specific formats.

Then use these environment variables as parameter like {{timestamp}} or {{date}}

Another need could be to access the time in milliseconds. Add below code in ‘Pre-Request Script’ tab and in it can be accesses as variable.

Leave a Reply

Your email address will not be published. Required fields are marked *