I want to give current date as a value for (date = current date) parameter in GET request
Hey @immanuelsamuel
Welcome to the community!
Your question isn’t really giving people enough information to help you out.
Can you take a look through this post and edit your question and provide more context and detail please.
Welcome to the community
As Danny suggested above, kindly read that post and make sure to give enough details when you post a query.
But from the info you have provided, I think you are trying to pass a variable with current date every-time you run the GET request.
Please include the below snippet in your pre-request Script section.
var moment = require('moment');
pm.environment.set('currentdate', moment().format(("YYYY-MM-DD")));
{{$timestamp}}
-> predefined variable gets the current timestamp, Since you need date the above one should work.
use the parameter {{currentdate}}
in your GET request.
If you are having a different issue, kindly provide more details.
@bpricilla
You perfectly understood my question, yeah from now on I will try to give more details.
But the answer you provided is not working it’s throwing the below error.
@immanuelsamuel: Kindly edit the quotes. Its issue with copy paste here. It should look like:
@bpricilla
It works wonderfully now, thanks @bpricilla.
Just a friendly word of advice - If you’re sharing code snippets on here just simply wrap the code block in 3 backticks (```) by doing this you don’t get the formatting issues that you’re seeing.
It makes it 100% more readable
For example:
without backticks
{
“test”: message
}
with backticks
{
"test":"message"
}
Sure Danny, noted Thanks for sharing that.
may this blog help you https://dannydainton.com/2018/05/21/hold-on-wait-a-moment/ @immanuelsamuel
This worked. How can we convert it to UTC ?
suppose the time we get is in IST.
Hi @bpricilla
Could you please let me know how I can change this variable from current date to 10 days ago?
I need to load some data that the date is always 10 days ago from current time.
Thank you so much!
Fei
@chinajohi Welcome to the community Similar query is answered here, can you please check this:
Hi,
I need to have the current date and timestamp generated in my prescript to derive a control key, also need to use the same date and timestamp in the GET request Params.
I have tried this
var moment = require(‘moment’)
pm.environment.set(‘timestamp’, moment().format((“YYYY-MM-DDTHH:MM:SS”)));
But this is the time i see generated always
2021-09-20T14:09:68
2021-09-20T14:09:76
2021-09-20T14:09:83
2021-09-20T14:09:66
2021-09-20T14:09:80
However my current time is 2021-09-20T14:41:00
Can you please help me with generating current time in the format “YYYY-MM-DDTHH:MM:SS-HH:MM” or “YYYY-MM-DDTHH:MM:SS”?
Hi @niavarghese20,
In Moment.js, MM
is the token for displaying month which is why it’s showing you 09 (September) every time. If you change it to mm
then you will get the correct minute value.
The full format reference guide can be found here:
https://momentjs.com/docs/#/displaying/
Hey Thanks that worked
For all those who are interested in video explanationpass current date as value explained
hi i need to pass timestamp and +30 minutes in the same api
What have you tried so far? This topic has various example of using Moment including links to the full reference documentation.
What part are you struggling with?
If you are new to Postman. I would recommend going through the Postman training if you haven’t done so yet.
Postman Galaxy Training | Postman API Network
Run through the “APIs 101 Training”, then the “Testing and Automation Training” course.