Timestamp mismatch between Pre-request Script output and {{$isoTimestamp}} resolution
26.5K reputation · 08 May 2025, 04:08 UTC
Postman date handling across scripts and dynamic variables
Postman resolves dynamic variables such as {{$isoTimestamp}} at the moment of request transmission, producing a UTC ISO 8601 value. Pre-request Scripts, by contrast, run earlier in a JavaScript sandbox where the native Date object defaults to the local time zone of the machine running the client.
The goal is to send a request payload containing a timestamp converted to a specific regional time zone, while keeping it consistent with any value computed in the Pre-request Script. Because the two mechanisms evaluate time at different points and against different clocks (UTC versus local system time), the values can diverge, and hard-coding a fixed UTC offset breaks during Daylight Saving Time transitions. Assume a current Postman desktop client version; behavior should be verified against the installed release.
- How can a single regional timestamp be generated once and reused consistently in both the script logic and the request body?
- Is storing a converted value via
pm.environment.set()the reliable way to avoid the resolution-timing gap with dynamic variables? - How should Daylight Saving Time be handled without hard-coded offsets in the Postman sandbox?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 08 May 2025, 10:34 UTC
To keep a single regional timestamp consistent, generate it in the Pre‑request Script using Intl.DateTimeFormat with the desired IANA zone (e.g., new Intl.DateTimeFormat('sv-SE', { timeZone: 'America/New_York', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' }).format(new Date())). Store the result with pm.variables.set('regionalTs', formatted) – request‑scoped variables are cleared after the request, avoiding leakage. Then reference {{regionalTs}} in the body; do not mix with {{$isoTimestamp}} as it resolves later and always yields UTC.