I’m currently working with a rails 3.0.x app that’s recently been upgraded from rails 2.x. Recently, it has been discovered that our timestamps in MySQL have changed from being written in PST timezone offset to a UTC offset as a result of this migration.
After examining the problem it’s been decided we want to keep all our timestamps in a UTC format going forward. Unfortunately, we need to go through all our old records that have timestamps in PST and convert them to UTC (a somewhat complicated process). I’d rather not re-invent the wheel if at all possible, which leads me to my question:
Has anyone written a utility to handle conversion of PST timestamps to UTC timestamps for a MySQL database?
This is why you always save times in UTC and render them in the user’s local time if required. Sorry you had to find out the hard way!
What you could do is make a note of the
idvalues where the transition occurred, and then adjust all timestamps prior to that interval with the CONVERT_TZ() method in MySQL.That would look something like this for each table: