# Conversion of date value to number (16:08:00 =\> 58,080s)

**URL:** <https://discourse.nodered.org/t/conversion-of-date-value-to-number-1600-58-080s/38288>\
**Category:** General\
**Created:** [30 December 2020 15:14 UTC](https://discourse.nodered.org/t/conversion-of-date-value-to-number-1600-58-080s/38288 "2020-12-30T15:14:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FrantaD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frantad/32/34045_2.png) [@FrantaD](https://discourse.nodered.org/u/FrantaD)\
**Post date:** [30 December 2020 15:14 UTC](https://discourse.nodered.org/t/conversion-of-date-value-to-number-1600-58-080s/38288/1 "2020-12-30T15:14:36Z")

</div>

Hi,

I need to convert time from DATE format to NUMBER format (number of seconds). I will try to explain with a picture (the image is simulated using input).

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e74a3c004d4258f55e301a332eee79e599e7d2dc.png)

Please help create a code that:

- convert DATE to STRING (this works: `var sunrise={"payload":msg.start.toString()};`)
- split STRING into hour, minute, second (this works too: `var V_hour={"payload" :vychod.payload.slice(16, 18)}`)
- convert STRING to NUMBER
- multiply the hours and minutes to reach the second
- addition

Thank you for your help  
Frantisek

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 December 2020 15:38 UTC](https://discourse.nodered.org/t/conversion-of-date-value-to-number-1600-58-080s/38288/2 "2020-12-30T15:38:37Z")

</div>

Welcome to the forum @FrantaD.

You can convert a javascript Date object to a milliseconds timestamp using  
`let sunrise = theDate.getTime()`  
It looks as if you are trying to get the number of seconds since the start of the day, in which case you first need to get the number of ms since the start of the day, by taking the modulus with 24 hours in ms  
`sunrise = sunrise % (24 * 3600000`)  
Then divide by 1000 to get seconds.

However, that seems a slightly unusual thing to need, can you explain why you need that?

---

<div class="post-metadata">

**Author:** ![FrantaD](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frantad/32/34045_2.png) [@FrantaD](https://discourse.nodered.org/u/FrantaD)\
**Post date:** [30 December 2020 20:08 UTC](https://discourse.nodered.org/t/conversion-of-date-value-to-number-1600-58-080s/38288/3 "2020-12-30T20:08:08Z")

</div>

Hi Colin,

That's exactly what I was looking for. Even better 🙂

And the reason for this transfer is the transfer of this information to the PLC via EtherNet/IP communication.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85de3994615613cfcc037cc1c9cc69f37e2a6d85.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a70c46ae996506eae2e1b1ff7f7da8ebdd4eddc2.png)

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 January 2021 20:08 UTC](https://discourse.nodered.org/t/conversion-of-date-value-to-number-1600-58-080s/38288/4 "2021-01-13T20:08:10Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
