How to set env variables 'Date from'? The same date can't be run twice or more. The date can be -+ 1 day

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:

Details (like screenshots):

How I found the problem:

I’ve already tried:var now = new Date();
var timestamp = now.toISOString();
pm.environment.set(“timestamp”, timestamp);

Can you please clarify what you are asking?

It’s unclear what you need help with.

Just to note, the timestamp that you have currently set is just that, a timestamp, not just the date.

It includes the seconds and minutes. Therefore is likely to be unique unless you run the request more that once in exactly the same second.

1 Like

Thanks for response!
Date should be different for every running. It’s not important if it will be 2 days ago or 5 days before current date.

At the moment, you have the date including the minute and second, therefore it will most likely be unique.

Do you need it to just be a date? yyyymmdd for example? What format does it need to be in? Postman includes the moment library, which allows you to format dates.

If you just do a random variable for a date up to five days ago, its not really a big enough sample, so quite likely to produce the same date on occasion.

If you can only go back five days, then it sounds like you can only run this five times. You can only guarantee the uniqueness five times and would have to include an IF statement as a pre-request script that checks the current date and sets it accordingly.

I guess this depends on how often is this going to be run?