Converting $timestamp to ISO 8601

How can I convert $timestamp to ISO8601 format in a pre-request script?

This page on Stack Overflow has a function to do it, but neither Date() nor toISOString() seem to be available.

Dynamic variables (like $timestamp) cannot be used in the Sandbox. You can only use them in the {{..}} format in the request URL / headers / body.


var dateIso = new Date().toISOString();

Good reference:


Me too!! I mean… for all ISO date needs, I fall back to the code snippet that @matt posted.

However, if I have to do heavy date lifting, Postman Sandbox has the powerful “moment” library built in - more at

var moment = require('moment');

Docs of moment:


Thank you. That worked beautifully!

@shamasis, Thank you, I’ll check that when I have some free time.

Moment is pretty great.

I use this pre-request snippet to generate a timestamp from the previous day:

var moment = require('moment');
var ISO_8601_OFFSET = 'YYYY-MM-DDTHH:mm:ss.SSS';
var momentdate = moment().subtract(1, 'days').format(ISO_8601_OFFSET);

pm.environment.set("timestampUtcIso8601", momentdate+'Z');

Awesome stuff @murdoc-she-wrote,

You could reduce that down even further :wink:

var moment = require('moment');
pm.environment.set("timestampUtcIso8601more", `${moment().subtract(1, 'days').format()}Z`);