# Counter by day shift and night shift

**URL:** <https://discourse.nodered.org/t/counter-by-day-shift-and-night-shift/74581>\
**Category:** General\
**Created:** [2 February 2023 04:38 UTC](https://discourse.nodered.org/t/counter-by-day-shift-and-night-shift/74581 "2023-02-02T04:38:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atiki.nokin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/atiki.nokin/32/75382_2.png) [@atiki.nokin](https://discourse.nodered.org/u/atiki.nokin)\
**Post date:** [2 February 2023 04:38 UTC](https://discourse.nodered.org/t/counter-by-day-shift-and-night-shift/74581/1 "2023-02-02T04:38:43Z")

</div>

Hello, I'm new in node red so basically I just understand to make counter by shift just using if, else if logic only but I've confused how to use the time format because it depends on AM PM format, can you help me what can I learn to make the counter by shift with other logic?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 February 2023 05:01 UTC](https://discourse.nodered.org/t/counter-by-day-shift-and-night-shift/74581/2 "2023-02-02T05:01:34Z")

</div>

Hi.

I see you are a _busy little bee_.

The _timeformat_ is a called `timestamp` and is a number/value which is unique to _NOW_.  
I think it shows the value in milliseconds since..... a fixed date way back when.  
So no two values can/will ever be the same.

There is a `moment` node which translates from `timestamp` to human readable.  
That may help. Not sure.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [2 February 2023 07:25 UTC](https://discourse.nodered.org/t/counter-by-day-shift-and-night-shift/74581/3 "2023-02-02T07:25:54Z")

</div>

Can you share what have you done so far?

---

<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:** [2 February 2023 11:37 UTC](https://discourse.nodered.org/t/counter-by-day-shift-and-night-shift/74581/4 "2023-02-02T11:37:18Z")

</div>

If you have timestamps as strings, you need to use the JavaScript `Date` functions to turn them back into JavaScript Date objects which, as Andrew has said, is a number of milliseconds since midnight January 1, 1970, UTC.

[Date - JavaScript | MDN (mozilla.org)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)

Date/Time calculations can get very complex and have lots of edge-cases so we really need to know more about what you want to achieve with the calculations in order to really be able to help. It is easy enough to use JS Date values to calculate elapsed ms. But something entirely different if you need to be able to translate that to a real date/time (due to daylight savings, leap-years, etc) and even more complex if you need to handle timezones.

---

<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:** [3 April 2023 11:38 UTC](https://discourse.nodered.org/t/counter-by-day-shift-and-night-shift/74581/5 "2023-04-03T11:38:01Z")

</div>

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