# HTTP Requests --\> Script mode How can I add date variable in HTTP Get request

**URL:** <https://community.dynatrace.com/t/http-requests-script-mode-how-can-i-add-date-variable-in-http-get-request/36938>\
**Category:** Synthetic Monitoring\
**Tags:** http-monitor, synthetic-monitoring\
**Created:** [October 18, 2022, 11:01am UTC](https://community.dynatrace.com/t/http-requests-script-mode-how-can-i-add-date-variable-in-http-get-request/36938 "2022-10-18T11:01:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vabg](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vabg](https://community.dynatrace.com/u/vabg)\
**Post date:** [October 18, 2022, 11:01am UTC](https://community.dynatrace.com/t/http-requests-script-mode-how-can-i-add-date-variable-in-http-get-request/36938/1 "2022-10-18T11:01:19Z")

</div>

I have this request and I want to use pick current date every time instead of hardcoding this value, I tried using&nbsp;api.setValue(“currentDate”, api.dateToFormat(api.date(), “dd/MM/yy”)); but its giving syntax error.

Please let me know how can I achive this, basically in from and to in below URL I want it to pick current date everytime.

{  
“version”: “1.0”,  
“requests”: [  
{  
“description”: “dev.testazure.test/test-service”,  
“url”: “[https://dev.testazure.test/test-service/api/v1/eventhistory/notification?from=2022-09-12T04:35:51-0400&to=2022-09-12T05:35:51-0400](https://dev.testazure.test/test-service/api/v1/eventhistory/notification?from=2022-09-12T04:35:51-0400&to=2022-09-12T05:35:51-0400)”,  
“method”: “GET”,  
“validation”: {  
“rules”: [  
{  
“value”: “\>=400”,  
“passIfFound”: false,  
“type”: “httpStatusesList”  
}  
]  
},

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [October 18, 2022, 12:13pm UTC](https://community.dynatrace.com/t/http-requests-script-mode-how-can-i-add-date-variable-in-http-get-request/36938/2 "2022-10-18T12:13:32Z")

</div>

Hi [@vabg](https://community.dynatrace.com/user/55999) , good day.

To achieve this, you first need to set the variable in [pre-execution script](https://www.dynatrace.com/support/help/how-to-use-dynatrace/synthetic-monitoring/http-monitors/pre-and-post-scripting-for-http-monitors#date-formatting), and then refer the variable in the URL, like this:

 ![Screen Shot 2022-10-18 at 09.11.28.png](https://global.discourse-cdn.com/dynatrace/original/2X/1/1dea5b0f3d3eb645c4b4a66e5952acc158ee39d2.png)

you can add any number of variables there to replace your requests params according.

Also, do confirm the proper date format syntax, and [use this](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html) to get the right one.

based on the example you sent, your pre-execution script would be like:

api.setValue(“dateToFormatCurrentDate”, api.dateToFormat(api.date(), “yyyy-MM-dd’T’HH:mm:ss”));

Please try and let us know.

---

<div class="post-metadata">

**Author:** ![vabg](https://avatars.discourse-cdn.com/v4/letter/v/58956e/32.png) [@vabg](https://community.dynatrace.com/u/vabg)\
**Post date:** [October 18, 2022, 2:43pm UTC](https://community.dynatrace.com/t/http-requests-script-mode-how-can-i-add-date-variable-in-http-get-request/36938/3 "2022-10-18T14:43:39Z")

</div>

Hi&nbsp;[@dannemca](https://community.dynatrace.com/user/18264)

Thanks for your help, its working fine.

Could you please also let me know if we have any method to return previous day date like api.date return present date

Thanks

---

<div class="post-metadata">

**Author:** ![dannemca](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/dannemca/32/7215_2.png) [@dannemca](https://community.dynatrace.com/u/dannemca)\
**Post date:** [October 18, 2022, 4:55pm UTC](https://community.dynatrace.com/t/http-requests-script-mode-how-can-i-add-date-variable-in-http-get-request/36938/4 "2022-10-18T16:55:56Z")

</div>

You can “go crazy” using pre/post-execution script. You can do some math and calculate the previous date based on current date. It may requires some scripting skills, but doable.

Also, do check if the API you are calling does allow you to transform the date interval, like Dynatrace API does, example, “from=-24h to now”, means all previous 24h.
