# How to add numbers to a date time string

**URL:** <https://discourse.nodered.org/t/how-to-add-numbers-to-a-date-time-string/19982>\
**Category:** General\
**Created:** [6 January 2020 19:13 UTC](https://discourse.nodered.org/t/how-to-add-numbers-to-a-date-time-string/19982 "2020-01-06T19:13:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [6 January 2020 19:13 UTC](https://discourse.nodered.org/t/how-to-add-numbers-to-a-date-time-string/19982/1 "2020-01-06T19:13:10Z")

</div>

this script gives a date time stamp  
6-1-2020 tijd: 20:6:11

i want  
06-01-2020 tijd: 20:06:11 (extra 0 before day, month, hour etc.)  
is this possible?

var today = new Date();  
var date = today.getDate() +'-'+(today.getMonth()+1) +'-'+ today.getFullYear();  
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();  
msg.dateTime = date+' tijd: '+time;  
return msg;

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 January 2020 19:28 UTC](https://discourse.nodered.org/t/how-to-add-numbers-to-a-date-time-string/19982/2 "2020-01-06T19:28:43Z")

</div>

You can use `padStart(2, '0')`

> **[String.prototype.padStart()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)**
>
> The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [6 January 2020 19:49 UTC](https://discourse.nodered.org/t/how-to-add-numbers-to-a-date-time-string/19982/3 "2020-01-06T19:49:45Z")

</div>

Take the [moment node](https://flows.nodered.org/node/node-red-contrib-moment), in the output string you can make the output as you want.

[https://momentjs.com/docs/#/displaying/format/](https://momentjs.com/docs/#/displaying/format/)

---

<div class="post-metadata">

**Author:** ![pvanklink](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pvanklink](https://discourse.nodered.org/u/pvanklink)\
**Post date:** [7 January 2020 15:32 UTC](https://discourse.nodered.org/t/how-to-add-numbers-to-a-date-time-string/19982/4 "2020-01-07T15:32:28Z")

</div>

thanks! Works!
