Date, variable and url

Hello,

I have 2 questions :

1/ I would like to define a variable as the date -4 days, so I know I have to use executeScript and the following command, but how to define the date - 4 days ?
executeScript | var d=new Date(); return d.getDate()+’/’+((d.getMonth()+1))+’/’+d.getFullYear();

2/ Then I would like to use this variable inside the folowing url where I have to replace the 3 sample with the same variable “date” and then open this url :

https://sellercentral.amazon.fr/gp/site-metrics/report.html#&cols=/c0/c1/c2/c3/c4/c5/c6/c7/c8/c9/c10/c11/c12/c13/c14/c15&sortColumn=16&filterFromDate=11/03/2020&filterToDate=11/03/2020&fromDate=11/03/2020&toDate=11/03/2020&reportID=102:DetailSalesTrafficByChildItem&sortIsAscending=0&currentPage=0&dateUnit=1&viewDateUnits=ALL&runDate=

Thanks for your help !

This will get you the date -4 days in the format mm/dd/yyyy:

executeScript_Sandbox | var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * -4); var m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); m=m+"/"+d.getDate().toString().padStart(2, "0")+"/"+d.getFullYear(); return m | myvariable

You can now put that date wherever you would need it:

mywebsite.com/fromdate${myvariable}/test

1 Like

Ok, thanks for your help !

Hello,

Just one last question, if I need the date -4 days in the format dd/mm/yyyy ?

Thanks :slight_smile:

Just reverse the month and day:

executeScript_Sandbox | var d= new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * -4); var m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); m=d.getDate().toString().padStart(2, "0")+"/"m+"/"+d.getFullYear(); return m | myvariable

1 Like