APIs & Integrations

ablansett
Member

Problem with Invalid dates.

SOLVE

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

 

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

 

 

Which obviously is not what I want.

 

Any ideas on how to resolve this?

0 Upvotes
1 Accepted solution
ablansett
Solution
Member

Problem with Invalid dates.

SOLVE

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;

 

View solution in original post

3 Replies 3
himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Problem with Invalid dates.

SOLVE
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
Digital Marketing & Inbound Expert In Growth Hacking Technology
0 Upvotes
ablansett
Member

Problem with Invalid dates.

SOLVE

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();
ablansett
Solution
Member

Problem with Invalid dates.

SOLVE

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;