Limit to the strtotime function in php

Asked

Viewed 237 times

4

I’m using the strtotime function as an example below, with cakephp. by spending the sum of 50 years is returning null, the most I can return is adding 20 years.

Would anyone know if this is a limitation/configuration of cakephp or php itself?

date('d/m/Y', strtotime('+50years'));
  • I have the slight impression that this has already been answered. There is no problem in the question being duplicated, but it is important to already demonstrate here the content existing on the site :D

1 answer

6


According to the documentation the limit of the function date() is 19/01/2038, because PHP uses a 32-bit integer to represent that date.

To get around the problem use the class Datetime, in the example below was added a period of 50 years(P50Y).

$data = new DateTime();
$data->add(new DateInterval('P50Y'));
echo $data->format('d/m/Y'); //25/01/2066
  • I was going to ask if it would be better to use datetime kk know if there is any limit to it? + 1

  • 1

    @lvcs remember the bug of the year 2000? there is another, bug of 2038.

  • thanks for the rray return.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.