Php call to date function echos tomorrow

This standard, published, code echos tomorrow’s date on my Windows 8.1 HP Envy laptop - which reports the date is actually today’s date. What the heck is going on?

I am doing this on Monday June 15, 2015 and the resulting echo’d statement (through IE, FireFox, and Chrome) is Tuesday June 16th, 2015…

Ideas?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Today's Date</title>
  </head>

  <body>
    <p>
      Today's date (according to this web server) is
      <?php echo (date('l F jS Y.')); ?>
    </p>
  </body>
</html>

What timezone is the server using and what timezone are you in? Perhaps you are still in yesterday compared to where the server is.

UTC-7 USA Mountain. SErver is my laptop - sandbox running XAMPP

And the time shown in the corner of your screen and the timezone in your ini are correct?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Today's Date</title>
  </head>

  <body>
    <p>
      Today's date (according to this web server) is
      <?php echo (date('l F jS Y.')); ?>
    </p>
  </body>
</html>

What is 'l F jS Y.' meant to display?

Yes, the date and time on my laptop are correct - today’s date & time.

This code is supposed to show Monday, June 15th 2015 and it shows Tuesday, June 16th, 2015

darned strange…

Not if your web server is using UTC and the rest of the computer is seven hours behind. It would mean that it would swap days at 5pm your time instead of midnight.

Web servers do not use the same timezone as that set in the operating system - unless you specifically set both the same. Setting a web server to use UTC is quite common as visitors can come from anywhere in the world and that is the standard timezone that all your visitor’s timezones are measured from.

How would I check that Setting? Great idea, never thought of it.

try
echo date_default_timezone_get();

PERFECT! That was it! Found the config setting in php.ini and now all works as expected.

Guess it is tomorrow in Berlin…

Thanks again!

1 Like

Yes, but Berlin is UTC -1 (-2 in summertime).
UTC = is Greenwich Mean Time (London).

You mean +1 and +2.

Yes :smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.