Reputation: 1632
I want to convert 12/31/2099
to Unix time using PHP. I tried strtotime('12/31/2099')
but the function returns null
.
I tried converting it to Unix time using an online conversion tool which gives 4102358400
which, when turned into a date gives 01/18/2038
.
How can I convert dates to Unix time and again convert it back to a readable format like 12/31/2099
?
Upvotes: 0
Views: 448
Reputation: 28906
In old versions of PHP ( < 5.1.0), strtotime supported a max date of Tue, 19 Jan 2038 03:14:07 UTC. To bypass this limitation, upgrade to 5.1.0 or later.
64-bit versions are unaffected by this limitation.
For more information, see the Notes: at http://www.php.net/strtotime
Upvotes: 2
Reputation: 65274
The unix timestamp of a point in time is the number of seconds since 1970-01-01 00:00:00 UTC to this point in time. On 2038-01-18 this will overflow a 32bit signed int - call it the Y2K bug of the unices.
Mind though, that this is a problem of the implementation, not the algotithm: Most current implementations use an unsigned 32bit int, but it is to be expected that 32bit ints will be a thing of the past some time before 2038
Usual workarounds include an if-branch to detect whether a date is after the wraparound and adjust accordingly.
Upvotes: 1
Reputation: 272467
32-bit Unix timestamps run out in 2038, so if you're on a 32-bit system, that would cause a problem.
Upvotes: 1