How to pass current date as a value in GET request

I want to give current date as a value for (date = current date) parameter in GET request

Hey @immanuelsamuel

Welcome to the community! :wave:

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.

1 Like

@immanuelsamuel:

Welcome to the community :wave:

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.

12 Likes

@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:

3 Likes

@bpricilla
It works wonderfully now, thanks @bpricilla.

1 Like

Just a friendly word of advice :smile: - 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 :smile:

For example:

without backticks :no_entry:

{
“test”: message
}

with backticks :trophy:

{
    "test":"message"
}
5 Likes

Sure Danny, noted :grinning: Thanks for sharing that.

may this blog help you https://dannydainton.com/2018/05/21/hold-on-wait-a-moment/ @immanuelsamuel :slight_smile:

This worked. How can we convert it to UTC ?
suppose the time we get is in IST.

Hello @akshaykhard777,

Welcome to the community :partying_face:

“toUTCString()” method should work :blush:

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 :partying_face: Similar query is answered here, can you please check this:

1 Like

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/

3 Likes

Hey Thanks :slight_smile: that worked

1 Like

For all those who are interested in video explanationpass current date as value explained

1 Like

hi i need to pass timestamp and +30 minutes in the same api

@sivakailashgotham

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.

I have prepared this small vidoe explanation.

Hope it helps.
Thank you.

1 Like