# Timestamp for following noon

**URL:** <https://discourse.nodered.org/t/timestamp-for-following-noon/58297>\
**Category:** General\
**Created:** [14 February 2022 08:03 UTC](https://discourse.nodered.org/t/timestamp-for-following-noon/58297 "2022-02-14T08:03:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![davenrea](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davenrea/32/32842_2.png) [@davenrea](https://discourse.nodered.org/u/davenrea)\
**Post date:** [14 February 2022 08:03 UTC](https://discourse.nodered.org/t/timestamp-for-following-noon/58297/1 "2022-02-14T08:03:11Z")

</div>

Hi

I'm struggling to work out how to generate a time stamp for the next noon. Any help would be appreciated, ideally a node if anyone know of one.

thanks

---

<div class="post-metadata">

**Author:** ![davenrea](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davenrea/32/32842_2.png) [@davenrea](https://discourse.nodered.org/u/davenrea)\
**Post date:** [14 February 2022 08:29 UTC](https://discourse.nodered.org/t/timestamp-for-following-noon/58297/2 "2022-02-14T08:29:37Z")

</div>

Solved, someone sent me the below which he modified from something he found on the forum

// Get current time in millisecs since Jan 1st 1970  
var now = Date.now();

// Calculate the timestamp of midnight at the _start_ of today:  
var tstamp = Math.floor(now/86400000)\*86400000;

// Add on 36 hours from last midnight to get to noon tomorrow  
tstamp += 129600000;

msg.payload = tstamp  
return msg;

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 February 2022 08:32 UTC](https://discourse.nodered.org/t/timestamp-for-following-noon/58297/3 "2022-02-14T08:32:54Z")

</div>

You can also get the midnight value like this.

```auto
var d = new Date();
d.setHours(0, 0, 0, 0);

```

I was wondering if you meant noon tomorrow, or the next noon: today or tomorrow.

---

<div class="post-metadata">

**Author:** ![davenrea](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davenrea/32/32842_2.png) [@davenrea](https://discourse.nodered.org/u/davenrea)\
**Post date:** [14 February 2022 08:34 UTC](https://discourse.nodered.org/t/timestamp-for-following-noon/58297/4 "2022-02-14T08:34:18Z")

</div>

I was looking for next noon so could be in 1 minute or 23 hours 59 minutes, thanks

---

<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:** [14 February 2022 09:42 UTC](https://discourse.nodered.org/t/timestamp-for-following-noon/58297/5 "2022-02-14T09:42:31Z")

</div>

I think that gives you noon tomorrow in London. If you want noon local time and am not in GMT timezone then you will have to adjust for that.

---

<div class="post-metadata">

**Author:** ![davenrea](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/davenrea/32/32842_2.png) [@davenrea](https://discourse.nodered.org/u/davenrea)\
**Post date:** [14 February 2022 10:56 UTC](https://discourse.nodered.org/t/timestamp-for-following-noon/58297/6 "2022-02-14T10:56:50Z")

</div>

Colin

Thanks, I have seen a floor in it!! I don't actually mind it it is an hour either side, just looking at solar irridation for the day ahead. On the basis the result is only needed between midnight and 7am I think I would get away with changing tstamp += 129600000 to tstamp += 43200000 which will give me midday the same day

---

<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:** [15 April 2022 10:56 UTC](https://discourse.nodered.org/t/timestamp-for-following-noon/58297/7 "2022-04-15T10:56:51Z")

</div>

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