I’m having trouble with date validation when submitting contact information to HubSpot’s API. The system keeps rejecting my timestamp saying it’s not at midnight UTC, but when I verify the timestamp using online converters, it shows the correct midnight time.
The error message I get looks like this:
“1505779200 is at 10:16:19.200 UTC, not midnight!”
Here’s my C# method for converting DateTime to UTC timestamp:
public static double ConvertToUnixTimestamp(System.DateTime inputDate)
{
inputDate = System.DateTime.SpecifyKind(inputDate, DateTimeKind.Utc);
var unixTimestamp = ((DateTimeOffset) inputDate).ToUnixTimeSeconds();
return unixTimestamp;
}
I’ve double-checked the timestamp value and it appears to be correct when validated externally. Has anyone encountered this issue before? What might be causing the discrepancy between my generated timestamp and HubSpot’s validation?
first, check if your inputDate is already utc before converting. specifykind doesn’t actually convert timezones - it just tells the system how to interpret the datetime. if your original datetime is local time, you’ll need touuniversaltime() first.
That timestamp 1505779200 converts to September 19, 2017 00:00:00 UTC - it’s midnight. But the error shows 10:16:19.200, so HubSpot’s probably reading your timestamp in a different timezone or adding milliseconds somehow. I’ve seen this before where the API wanted the timestamp as a string instead of a number. Check if HubSpot needs it formatted as a string, and make sure you’re hitting the right field - custom properties vs standard contact fields sometimes expect totally different formats. Also check if anything’s messing with your timestamp before it gets to HubSpot’s servers.
You’re probably losing or adding milliseconds during conversion. HubSpot’s API wants exact midnight timestamps, but your conversion is likely sneaking in fractional seconds.
Try forcing the time components to zero before converting:
var midnightDate = new DateTime(inputDate.Year, inputDate.Month, inputDate.Day, 0, 0, 0, DateTimeKind.Utc);
var unixTimestamp = ((DateTimeOffset) midnightDate).ToUnixTimeSeconds();
I’ve hit this same precision issue with other APIs. DateTime objects often carry leftover time data even when they look like midnight. Also check if your input DateTime got messed up by daylight saving transitions if it started as local time.