Problem with Invalid dates.

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

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.

Which obviously is not what I want.

Any ideas on how to resolve this?

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

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();

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;