Skip to content

Instantly share code, notes, and snippets.

@evandrix
Created October 10, 2012 05:00
Show Gist options
  • Save evandrix/3863256 to your computer and use it in GitHub Desktop.
Save evandrix/3863256 to your computer and use it in GitHub Desktop.
Epoch to MSSQL DateTime (hex)
#1262166663 / 2009-12-30 09:51:03.000
epoch = 1262166663L
# 70 years = 2,208,988,800 seconds, 01-01-1900 00:00 to 01:01-1970 00:00
offset = 2208988800L
actual = epoch + offset # no. secs since 1st Jan 1900
num_days = actual / 86400
num_secs = 300*(actual % 86400)
mssql_dt = "0x"+("%08x%08x"%(num_days,num_secs)).upper()
assert mssql_dt == "0x00009CEF00A25634"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment