# passing timestamp variable through API.

**URL:** <https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821>\
**Category:** APIs & Integrations\
**Tags:** contacts\
**Created:** [October 5, 2021, 7:52am UTC](https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821 "2021-10-05T07:52:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![EShumely](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/eshumely/32/78108_2.png) [@EShumely](https://community.hubspot.com/u/EShumely)\
**Post date:** [October 5, 2021, 7:52am UTC](https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821/1 "2021-10-05T07:52:33Z")

</div>

I’m pulling the data from a google sheet.

this is an example of a value - 10/4/2021 16:10:23

How do I pass this as a date? I haven’t done this before so I have no experience with converting dates. the examples I found weren’t working for me.

can you provide the right function for me to get the right date format?

Thanks. (I read HubSpot page about it, bcz I have no experience with dates the info they provided didn’t help)

---

<div class="post-metadata">

**Author:** ![davidoff2drew](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/davidoff2drew/32/80657_2.png) [@davidoff2drew](https://community.hubspot.com/u/davidoff2drew)\
**Post date:** [October 5, 2021, 5:17pm UTC](https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821/2 "2021-10-05T17:17:05Z")

</div>

I wouldn’t be able to give you a function without knowing how you’re building what you’re building. But, you can either set the time to 00:00:00 (or whatever equals UTC midnight for you), or remove the time part of the string and just send in the date string.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [October 5, 2021, 5:18pm UTC](https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821/3 "2021-10-05T17:18:16Z")

</div>

@EShumely

You will need to convert to unix timestamp in milliseconds

How you do it depends on what language you are using, but for a quick POC. you can use [this site](https://currentmillis.com/?)

@DanielSanchez , @piersg might have some advice 😀

---

<div class="post-metadata">

**Author:** ![EShumely](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/eshumely/32/78108_2.png) [@EShumely](https://community.hubspot.com/u/EShumely)\
**Post date:** [October 6, 2021, 5:17am UTC](https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821/4 "2021-10-06T05:17:51Z")

</div>

@dennisedson Thanks 🙂 I’m using js. I’ve tried everything I could find. Thanks for the reference but I tried that too. tried this link as well [https://www.epochconverter.com/](https://www.epochconverter.com//)

I think my lack of understanding of this object makes something very easy difficult for me.

firstly I don’t know what date am I getting, I don’t know what time zone it is. I don’t know how to convert it to UTC (thought I found something but it didn’t make any difference) I ended up using the error msg to get my UTC time and just hardcode the difference. but I don’t need to mention this is a horrible solution.

@davidoff2drew Hi David, I don’t like not being able to do something more than that, I don’t like being told that something can’t be done (someone from my team told me it’s not possible so now I am invested).

as for passing it as string, how would you filter based on a date if you passed them as string?

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [October 7, 2021, 1:49pm UTC](https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821/5 "2021-10-07T13:49:37Z")

</div>

@EShumely If you want to convert that date (including the time) directly in to a unix timestamp in JS, you could do this

```lia-code-sample
var date = '10/4/2021 16:10:23'
var unixDate = Math.floor(new Date(date).getTime() / 1000);
console.log(unixDate);
// returns "1633360223"

```

To follow up on @davidoff2drew’s suggestion, if the data from Google is always a string in the format “10/4/2021 16:10:23” then you could use the HubL split filter to remove the time. e.g.

```lia-code-sample
{% set dateAndTime = "10/4/2021 16:10:23" %}
{% set date = dateAndTime|split(' ') %}
{{date[0]}}

```

In JS, you can split a string like this:

```lia-code-sample
var date = '10/4/2021 16:10:23'
console.log(date.split(" ")[0]);
// returns "10/4/2021"

```

---

<div class="post-metadata">

**Author:** ![EShumely](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/eshumely/32/78108_2.png) [@EShumely](https://community.hubspot.com/u/EShumely)\
**Post date:** [October 10, 2021, 6:08am UTC](https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821/6 "2021-10-10T06:08:54Z")

</div>

Thanks 🙂 have you tried your solution? the value on my google sheet look like time - 10/7/2021 8:07:39

when I log this value it looks like this -

Mon Jul 12 15:32:28 GMT+03:00 2021

I couldn’t use the split function on that so I used to toLocalString so would be able to get only the date.

I assumed if I pass only the date string to this

`var unixDate = Math.floor(new Date(date).getTime() / 1000);​`

I will get the right value. but it still gave me this error - \> “1626037200 is at 19:40:37.200 UTC, not midnight!”

Any thoughts? I must be missing something. it is driving me crazy

---

<div class="post-metadata">

**Author:** ![EShumely](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/eshumely/32/78108_2.png) [@EShumely](https://community.hubspot.com/u/EShumely)\
**Post date:** [October 10, 2021, 10:47am UTC](https://community.hubspot.com/t/passing-timestamp-variable-through-api/44821/7 "2021-10-10T10:47:03Z")

</div>

@piersg that’s similar to what I was thinking. if I pass just the date the hours will be midnight by default. but it wasn’t the case. even when I chose the hours as 0,0,0,0 it still wasn’t the right hours. finally today I got the answer.

there is a method called

setUTCHours and you need to use it.

var date = new Date(timestemp).setUTCHours(0, 0, 0, 0);
