Skip to content

Converting Ticks to a Timestamp

I recently had to deal with a SQLite database that stored the timestamps as ticks.  Having to first research what a tick is, I created a simple function that will convert a tick value to a timestamp or MySQL datetime value since I couldn’t find anyone else who had done such a thing yet.

You can download it here or view it below.

The only tricky part (aside from figuring out what a tick is) was calculating the number of ticks between 0001-01-01 to 1970-01-01. Also of note: a tick is apparently a popular way to store date/time values for Microsoft.

2 Comments
  1. So, if it was tricky to calculate “the number of ticks between 0001-01-01 to 1970-01-01″ can you save us the work and just reveal the answer? And I assume you took into account the missing two weeks between the Gregorian and Julian calendars? :)

    Cheers.
    tai / eastpole

    October 18, 2009
  2. Hi Tai,

    I didn’t actually keep the code I used to get the number, sorry! From what I remember, it should account for the missing two weeks (I do remember looking that up and reading about it on Wikipedia).

    I took it out of the code after getting the number to speed up the script, so that I’m not recalculating that number every time. I’ll be sure to keep things like that commented in the code in the future!

    October 18, 2009

Comments are closed.