# Problem with parse a string to DateTime

**URL:** https://discourse.nodered.org/t/problem-with-parse-a-string-to-datetime/8556
**Category:** General
**Created:** [3 March 2019 14:23 UTC](https://discourse.nodered.org/t/problem-with-parse-a-string-to-datetime/8556 "2019-03-03T14:23:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![howl](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@howl](https://discourse.nodered.org/u/howl)
#### Post date: [3 March 2019 14:23 UTC](https://discourse.nodered.org/t/problem-with-parse-a-string-to-datetime/8556/1 "2019-03-03T14:23:13Z")

</div>

Hello,  
from an application I get the date in the format "20111230T213000Z", how can I convert it in a function to a DateTime object to calculate with it etc.?  
var d = new Date('20111230T213000Z') does not work.

Holger

---

<div class="post-metadata">

### Author: ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)
#### Post date: [3 March 2019 14:41 UTC](https://discourse.nodered.org/t/problem-with-parse-a-string-to-datetime/8556/2 "2019-03-03T14:41:49Z")

</div>

> [@howl](#):
>
> 20111230T213000Z

It tends to be time string but somehow proper format is lost .  
The string format should be: `YYYY-MM-DDTHH:mm:ss.sssZ`  
If you cant get properly formatted string from source, you need to break this string into parts to make your time object. There is many ways to do this.  
As you are already using the function node, so do it by using string extracting methods.  
[https://www.w3schools.com/js/js\_string\_methods.asp](https://www.w3schools.com/js/js_string_methods.asp)

---

<div class="post-metadata">

### Author: ![howl](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@howl](https://discourse.nodered.org/u/howl)
#### Post date: [3 March 2019 14:49 UTC](https://discourse.nodered.org/t/problem-with-parse-a-string-to-datetime/8556/3 "2019-03-03T14:49:28Z")

</div>

Hello hotNipi,  
thanks for your fast answer. I tried it:

```auto
var d = new Date('2019-02-06T05:00:00.000Z');
var year = d.getYear();  
var month = d.getMonth();

```

but year is "119" and month ist "1"

Holger

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [3 March 2019 14:54 UTC](https://discourse.nodered.org/t/problem-with-parse-a-string-to-datetime/8556/4 "2019-03-03T14:54:11Z")

</div>

It might be worth re-reading [https://www.w3schools.com/js/js\_date\_methods.asp](https://www.w3schools.com/js/js_date_methods.asp)

---

<div class="post-metadata">

### Author: ![howl](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@howl](https://discourse.nodered.org/u/howl)
#### Post date: [3 March 2019 15:23 UTC](https://discourse.nodered.org/t/problem-with-parse-a-string-to-datetime/8556/5 "2019-03-03T15:23:39Z")

</div>

Yes, it works, thank you very much.  
Holger

---

<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: [3 March 2019 15:33 UTC](https://discourse.nodered.org/t/problem-with-parse-a-string-to-datetime/8556/6 "2019-03-03T15:33:17Z")

</div>

> [@howl](#):
>
> hank you very much

Also check out the node-red-contrib-moment node if you need a node for date/time conversions and simple calculations.
