# Problem with Invalid dates.

**URL:** <https://community.hubspot.com/t/problem-with-invalid-dates/19989>\
**Category:** APIs & Integrations\
**Tags:** object\
**Created:** [April 10, 2020, 2:48pm UTC](https://community.hubspot.com/t/problem-with-invalid-dates/19989 "2020-04-10T14:48:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ablansett](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ablansett/32/23733_2.png) [@ablansett](https://community.hubspot.com/u/ablansett)\
**Post date:** [April 10, 2020, 2:48pm UTC](https://community.hubspot.com/t/problem-with-invalid-dates/19989/1 "2020-04-10T14:48:48Z")

</div>

Ok so I am developing a pass through to connect HS with our internal system.

Our internal system sends me dates in this form in EST:

2020-04-21T00:00:00

So I have to convert it to UTC Unix Timestamp at midnight, no big deal

`moment(field).subtract('4 hours').utc().startOf('day').unix()`

This gives me the right date in UTC Unix time stamp, however gives me an error from the API

`{"validationResults":[{ "isValid":false,"message":"00001586822400 is at 8:47:2.400 UTC, not midnight!", "error":"INVALID_DATE", "name":"some_date_field" },]}`

When i put the date _ **00001586822400** _ in a convert it gives me the following

 ![date_converter.PNG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/7/77ed94dc9e5c2bbc6370a1ca86aafbec2b1c0bb2.png)

which as you can see is Midnight in UTC.

Now when I add trailing zeros to the Unix Timestamp like so:

`moment(field).subtract('4 hours').utc().startOf('day').unix() + '0000'`

I don’t get an error however my time is saved like so.

 ![wrong-dates.PNG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/3/d/3d4e87d815381224a66674678852451bee138348.png)

Which obviously is not what I want.

Any ideas on how to resolve this?

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [April 11, 2020, 10:04pm UTC](https://community.hubspot.com/t/problem-with-invalid-dates/19989/2 "2020-04-11T22:04:46Z")

</div>

Hello there,  
Try to create datetime object as per timezone of your HubSpot portal and then format it to midnight. There should be some method available to do so.  
Thanks

---

<div class="post-metadata">

**Author:** ![ablansett](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ablansett/32/23733_2.png) [@ablansett](https://community.hubspot.com/u/ablansett)\
**Post date:** [April 13, 2020, 1:45pm UTC](https://community.hubspot.com/t/problem-with-invalid-dates/19989/3 "2020-04-13T13:45:29Z")

</div>

Ok so I tried the following and it still gives me the same error.

`moment(field).startOf('day').unix();`

and

`moment(field).startOf('day').utc().unix();`

---

<div class="post-metadata">

**Author:** ![ablansett](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ablansett/32/23733_2.png) [@ablansett](https://community.hubspot.com/u/ablansett)\
**Post date:** [April 28, 2020, 2:21pm UTC](https://community.hubspot.com/t/problem-with-invalid-dates/19989/4 "2020-04-28T14:21:34Z")

</div>

My mistake, for some reason I was thinking that Unix TimeStamp was in miliseconds and not seconds.

Fix:

`moment(field).utc().startOf('day').unix() * 1000;`
