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?

+3


source to share


3 answers


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

.

+4


source


The problem is that you are using a function that cannot handle dates on a 32-bit system in the future.

Use DateTime instead, it will deal pretty happily with dates like this: -



$date = new \DateTime('2050-10-13');
var_dump($date);

      

Demo

+2


source


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.

+1


source







All Articles