# How to use two object values (date and time) to make timestamp

**URL:** <https://discourse.nodered.org/t/how-to-use-two-object-values-date-and-time-to-make-timestamp/52958>\
**Category:** General\
**Created:** [29 October 2021 23:12 UTC](https://discourse.nodered.org/t/how-to-use-two-object-values-date-and-time-to-make-timestamp/52958 "2021-10-29T23:12:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shit5tain](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shit5tain/32/50210_2.png) [@shit5tain](https://discourse.nodered.org/u/shit5tain)\
**Post date:** [29 October 2021 23:12 UTC](https://discourse.nodered.org/t/how-to-use-two-object-values-date-and-time-to-make-timestamp/52958/1 "2021-10-29T23:12:20Z")

</div>

Hi,  
I have a msg with date and time separated in two elements, and I want to merge tha values from these two to be able to output a timestamp. Anybody know how I can make that happen in a function node?

msg.payload.originalDate: "2021-10-30"  
msg.payload.originalTime: "21:30:00.000"  
I want to use these values to output this timestamp 1635622200000

Here was my first try and of course it didn't work, but hopefully it shows what I want to accomplish.

var date = msg.payload.originalDate  
var time = msg.payload.originalTime  
var alarm = new Date(date, "T", time)

var msg2 = {payload: alarm.getTime()};

With this configuration instead of the one above  
var alarm = new Date(date)  
I get a timestamp output, but I just can't figure out how to get the time in there aswell.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 October 2021 23:23 UTC](https://discourse.nodered.org/t/how-to-use-two-object-values-date-and-time-to-make-timestamp/52958/2 "2021-10-29T23:23:48Z")

</div>

> [@shit5tain](#):
>
> var alarm = new Date(date, "T", time)

```auto
var alarm = new Date(date + "T" + time)

```

You need to concatenate the strings

> **[3 Ways to Concatenate Strings in JavaScript](https://masteringjs.io/tutorials/fundamentals/string-concat)**
>
> You can concatenate strings in JavaScript using the \`+\` operator, the \`Array#join()\` function, or the \`String#concat()\` function. Here's what you need to know.

---

<div class="post-metadata">

**Author:** ![shit5tain](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shit5tain/32/50210_2.png) [@shit5tain](https://discourse.nodered.org/u/shit5tain)\
**Post date:** [29 October 2021 23:29 UTC](https://discourse.nodered.org/t/how-to-use-two-object-values-date-and-time-to-make-timestamp/52958/3 "2021-10-29T23:29:20Z")

</div>

So close, but still so far away 😆  
With your help I finally got the result I wanted, thank you very much.

---

<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:** [12 November 2021 23:30 UTC](https://discourse.nodered.org/t/how-to-use-two-object-values-date-and-time-to-make-timestamp/52958/4 "2021-11-12T23:30:00Z")

</div>

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