0

I have tried the following code to find the day in a week.

<?php
$day = date('l', strtotime( $date));
?>

When I enter the date "12-25-2049", it says "Wednesday" but it should be "Saturday".
But when I enter the date "11-11-2014" or "2015" it gives the correct day of the week.

Why is the first date not working as expected?

showdev
  • 28,454
  • 37
  • 55
  • 73
Amit
  • 1
  • please post the actual code that you used. I do know that PHP tries to interpret dates. Your example looks like it can be parsed uniquely. Still, it would be nice to see what you actually did? PHP `DateTime` should do something sensible with that value. Did you try 'createFromFormat' ? – Ryan Vincent Nov 11 '15 at 17:43
  • @Amit you are giving it the wrong format for 2049 – Basheer Kharoti Nov 11 '15 at 17:49
  • 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. - http://de1.php.net/strtotime --- also see this: http://stackoverflow.com/questions/5319710/accessing-dates-in-php-beyond-2038 – m02ph3u5 Nov 11 '15 at 17:49

2 Answers2

1

Provide the correct date format

  $date = '25-12-2049';
  echo date('l', strtotime($date)); // satureday

Update

as @showdev suggested

$date = '12/25/2049'; //if the separator is a slash (/), then the American m/d/y is assumed
echo date('l', strtotime($date)); // satureday
Basheer Kharoti
  • 4,202
  • 5
  • 24
  • 50
  • 1
    For reference, "if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed." [PHP: strtotime notes](http://php.net/manual/en/function.strtotime.php#refsect1-function.strtotime-notes) – showdev Nov 11 '15 at 17:54
  • @showdev He was using dash(-) and he was providing the wrong format – Basheer Kharoti Nov 11 '15 at 17:57
  • Yes, I agree. I provided the documented explanation. – showdev Nov 11 '15 at 17:58
1

The PHP timestamp is limited to 2038, it must be the cause of your problem.

Here are more informations : Why do timestamps have a limit to 2038?

Community
  • 1
  • 1
Raphaël Vigée
  • 2,048
  • 14
  • 27
  • wider than PHP it's the unix timestamp issue: https://en.wikipedia.org/wiki/Year_2038_problem – Martin Nov 11 '15 at 17:55