What can I do in my code today, to prevent the unix time stamp running out in 2038? What can I do in my code today, to prevent the unix time stamp running out in 2038? unix unix

What can I do in my code today, to prevent the unix time stamp running out in 2038?


Store the timestamp as a 64bit, or higher, integer. I'm sure MySQL will be updated by then so that TIMESTAMP isn't 32bit. In regards to PHP, I don't see any issues there if you're on a 64 bit server.


Unless you plan on using a 32-bit server or PHP binary for the next 25 years I don't think it will be a problem.

PHP is an interpreted language, so when you write $stamp = 1358425440; it's just a string of text that PHP reads in, then allocates X bytes of memory to store it according to how PHP was compiled. So if you update your PHP binary to one that supports 64-bit integers then you don't have to change your code. [In theory, at least. We all know how PHP likes to change common functions around and deprecate things.]

The only consideration I can see making is for the storage of integer values outside of PHP, ie. in mySQL. In this case you just need to make sure that you're storing your timestamp as either an UNSIGNED INT, BIGINT, or DATETIME.

SIGNED INTs will conk out Tue, 19 Jan 2038 03:14:07 GMT, but UNSIGNED INTs will last until Sun, 07 Feb 2106 06:28:15 GMT.


Change

 // 32 bit    int timestampSec 

to

 // 64bit    long timestampSec

for internal storage.