Skip to content

Question regarding date values in postman-to-k6 converted scripts #123

Discussion options

You must be logged in to vote

Found the solution:

Instead of moment() use Date()
Created below method to do date additions.

const getDate = (days) => { const startDate = new Date() startDate.setDate(startDate.getDate() + days) return startDate.toISOString().slice(0, 10) }

This method returns date in "YYYY-MM-DD" format (e.g. "2024-03-28")
Calling this method to initiate Collection Variables:

pm.collectionVariables.set(
  "todaysDate",
  getDate(0)
);

pm.collectionVariables.set(
  "tomorrowsDate",
  getDate(1)
);

pm.collectionVariables.set(
  "yesterdaysDate",
  getDate(-1)
);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by prabodhkelkar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant