-1

I have a little trouble with strtotime, I have a date 18 july 1868 and when I record in the database, I make $date = strtotime (18-07-1868). But when I appear it, I dated ('Y-m-d', $date) but it does not show me 18-07-1868 but 13-12-1901.

How can I fix this problem?

Thx,

prava
  • 3,916
  • 2
  • 24
  • 35
user2969259
  • 13
  • 2
  • 6
  • 2
    Works for me: http://sandbox.onlinephpfunctions.com/code/c884add196158843434d12de5b0c65cadd17eb2a – WizKid May 30 '14 at 07:35
  • can you post your actual code? if you used `strtotime(18-07-1868);` I think that's invalid, you'd need to wrap it in a string. – totallyNotLizards May 30 '14 at 07:36
  • 1
    [`strtotime` will return a minus number as long as you're running PHP `5.2.6+`](http://3v4l.org/2maLV). If you're using any lower then please note that PHP 5.2 came out 2nd of November 2006 (8 years ago) and ended support on the 6th of January 2011. Over 3 years ago. – h2ooooooo May 30 '14 at 07:37
  • check this: http://stackoverflow.com/questions/7198539/php-strtotime-returning-false-for-dates-less-than-1900 – fortune May 30 '14 at 07:46
  • 1
    it's also worth noting that strtotime returns different output depending on 32 or 64 bit system - although I don't think that's the OP's problem. http://php.net/manual/en/function.strtotime.php – totallyNotLizards May 30 '14 at 07:51
  • If you're working with dates that fall outside the 32-bit range, use DateTime objects, not unix timestamps – Mark Baker May 30 '14 at 07:58

2 Answers2

1

From the manual:

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC.

(These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)

Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.

So it depends on the platform you're running it on. It needs to be 64 bit to exceed the range stated in the manual.

Community
  • 1
  • 1
bcmcfc
  • 25,966
  • 29
  • 109
  • 181
0

You are not putting a string (single quote or double quote) in strtotime() function...

Try This...

$x = strtotime('18-07-1868');
echo date('Y-m-d', $x);
TipuZaynSultan
  • 783
  • 4
  • 16