Welcome Guest, Not a member yet? Register   Sign In
The best way to store date/time in MySQL for use with 'date' helper?
#5

[eluser]WanWizard[/eluser]
There are a few sides to this issue.

First, you have the storage issue. 2038 is an issue because a timestamp is the number of seconds since 1-1-1970, and as the timestamp is a 32-bit integer, you'll run out of seconds to store in 2038. Solution, don't store it in 32-bits. For database fields, that means UNSIGNED INT(11).

Second issue is that the functions dealing with timestamps, all use this same 32-bit integer. Therefore things like "echo strtotime("11-11-2050");" don't work. This has been fixed some time ago for 64-bit platforms, so if you're using PHP on a 64-bit OS (both Linux and Windows), it's not a problem.
If you find a function that hasn't been fixed, in PHP5, you can (again) use the DateTime() class, as it uses 64-bit integer internally.

edit:
Just tested this on my development machine (Fedora 13 x86_64, PHP 5.3.2):
Code:
echo strtotime("11-11-2050"),'<br>';
echo date("Y-m-d", 2551734000);

Results
Code:
2551734000
2050-11-11
So no issues there...


Messages In This Thread
The best way to store date/time in MySQL for use with 'date' helper? - by El Forum - 06-15-2010, 01:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB