I’m having trouble sending date values to HubSpot’s contact API. When I try to submit a timestamp, the API throws an error message saying the UTC timestamp doesn’t represent midnight.
The error I get looks like this:
“1505779200 is at 10:16:19.200 UTC, not midnight!”
But when I check this timestamp using online conversion tools, it shows as exactly midnight UTC. This is confusing because the converter confirms it’s the right time.
Here’s my C# method for converting DateTime to Unix timestamp:
public static long ConvertToUnixTimestamp(DateTime inputDate)
{
inputDate = DateTime.SpecifyKind(inputDate, DateTimeKind.Utc);
var unixTime = ((DateTimeOffset)inputDate).ToUnixTimeSeconds();
return unixTime;
}
Has anyone encountered this issue before? I’m not sure why HubSpot is rejecting what appears to be a valid midnight timestamp.
Others mentioned milliseconds, but that’s just scratching the surface. You’ve got a much bigger issue - manual timestamp conversion is a nightmare that’ll keep biting you.
I’ve dealt with tons of API integrations, and HubSpot’s especially picky about date formats. Stop debugging timestamp code every time something breaks. I automated the whole thing.
Build a workflow that handles datetime conversion and manages API calls automatically. No more manual conversion headaches, no more worrying about milliseconds vs seconds or timezone weirdness.
The workflow validates timestamps before sending to HubSpot and auto-retries failed requests. You can log everything for debugging too.
I do this for all my API work now. Saves me hours of troubleshooting bizarre timestamp problems.
yeah, same thing happened to me. it’s probly a timezone issue - even though you’re converting to UTC, HubSpot might be interpreting it differently. try using ToUnixTimeMilliseconds() instead of seconds and see if that fixes it. also double-check your datetime object is actually set to midnight b4 converting.
You’re right about the milliseconds vs seconds issue, but there’s another gotcha. HubSpot’s contact properties are super strict about date formats. I hit this same problem last year and wasted hours debugging it. Your conversion method works fine for Unix timestamps, but HubSpot validates the raw number you send. When you send 1505779200, HubSpot reads it as milliseconds and calculates the wrong datetime. I ended up writing a separate method just for HubSpot that always returns milliseconds and validates the datetime is actually midnight UTC before sending. This caught several edge cases where my local datetime wasn’t set to midnight before conversion.
I encountered a similar issue recently, and it was quite perplexing. Your conversion method appears correct and should yield the right Unix timestamp. However, HubSpot expects timestamps in milliseconds, not seconds. The timestamp you mentioned, 1505779200, indeed represents midnight UTC on September 19, 2017, but HubSpot interprets it as a timestamp in milliseconds, which converts it incorrectly. To resolve this, just multiply your Unix timestamp by 1000 before sending it to the API. This adjustment should eliminate the validation error regarding midnight.