Date format storeeval


On page

I look this

var d= new Date(); var m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); d.getFullYear()+"-"+m+"-"+d.getDate();

For Get todays date in YYYY-MM-DD format

But i look the day is D not DD for today this storeeval give me 2019-04-7

How can I edit the javascript to obtain from 2019-04-7 to 2019-04-07 in date format ?


Hi I have this same issue with needing the 2 digit day and searched and found this post.
I ended up fixing it by adding this to the date:

.toString().padStart(2, "0")


d.getDate().toString().padStart(2, "0")

Just posting it so if anyone else searches

I solved with this code

  "Command": "executeScript_Sandbox",
  "Target": "var d = new Date();var m = ((d.getMonth()+1)<10) ? \"0\" + (d.getMonth()+1):(d.getMonth()+1);var day=d.getDate()<10 ? \"0\" + d.getDate():d.getDate();return day + \"-\" + m + \"-\" + d.getFullYear();",
  "Value": "Date"