January 19, 2038 03:14:07 GMT is now less than 20 years away. That's the time that UNIX's 32-bit timestamp rolls over. I'm working on designing some MySQL tables that may still be in use at that time.
This is the so-called Year 2038 problem.
It seems, from stuff I've tried on MariaDB 10.3, using the TIMESTAMP
datatype yields error 1292 (incorrect datetime value) for datestamps after the date rollover.
What is a good practice for designing these tables to be future-proof? I could use DATETIME
data, but TIMESTAMP
has some very useful features with respect to timezones.
Is there any chance some future version of MySQL (not to mention Linux and the other UNIX derivatives) will upgrade?
Use BigInts to store a unix timestamp. This is functionally equivalent to the TIMESTAMP type though lacking some of the sugar that is attached to that. However, if at the application level you're happy to just consume UNIX timestamps, it makes no difference at all and, for me so far at least, is trivial to handle at the database layer with the occasional UNIX_TIMESTAMP(…) / FROM_UNIXTIME(…) call. That will keep you going far beyond 2038.
Though I expect the MySQL / Maria mob will create some hack in version X.y that will automatically update TimeStamp fields as part of the upgrade path. It will probably be released on January the 18th, 2038, mind you. ;)
Anyway, if you want to future proof, BIGINT treated as a UNIX time stamp is your answer.