Strtotime returns false when converting date string
Using php 5.4.34 AND Laravel 4 with apache 2.2.22 and Ubuntu.
I am trying to convert a string '2050-10-13'
to a date and it always returns false.
var_dump(strtotime('2050-10-13')); ==> false
var_dump(strtotime('13-10-2050')); ==> false
var_dump(strtotime('2050/10/13')); ==> false
var_dump(strtotime('13/10/2050')); ==> false
I tried to add:
date_default_timezone_set('Europe/Brussels');
OR
date_default_timezone_set('Europe/Paris');
I am not changing anything.
in app/config/app.php
I have:
'timezone' => 'UTC',
'locale' => 'en',
What could be the problem?
source to share
2050
cannot be represented internally on 32-bit systems.
The timestamp is limited to 2038 because the maximum value for a 32-bit integer is 2,147,483,647
, that is:2038-01-19T03:14:08+0000Z
You just experienced an error year2038
.
How to fix
Don't use a timestamp. Instead, use a more robust library such as new \DateTime('2050-10-13');
and of course the Database Usage field Date
.
source to share
Adding a response to a dynamic response. The timestamp is limited to 2038 because the maximum value for a 32-bit integer is 2,147,483,647. If you add +1 to this, you get -2,147,483,647. 2 147 483 647 seconds from 01-01-1970 00:00:00 - January 19, 2038. If you add one more second, you get the date somewhere in 1902.
You're out of luck this time.
source to share