A Web Design Community curated by Chris Coyier

A little dab'll do ya

Code Snippets

Code Snippets > PHP > Adjust Server Time Submit one!

Adjust Server Time

Sometimes the time set on your server isn't accurate to what your local time is. If you can't change it, you can adjust it yourself.

$today = date('Y-m-d-G');
$today = strftime("%Y-%m-%d-%H", strtotime("$today -5 hour"));

If your server thought it was 12 midnight, but it was really 7 pm, this will roll the $today variable back five hours to be correct.

Subscribe to The Thread

  1. David says:

    The preferred way for PHP5 and above is to use:


    date_default_timezone_set('Europe/London');

    A list of the possible values are here:

    http://www.php.net/manual/en/timezones.php

  2. Yep, definitely use date_default_timezone_set(‘mytimezone’);

  3. Martin says:

    earthlink only hosts php 5.0.5 and that time zone changing function is not available… =\

    date_default_timezone_set

    (PHP 5 >= 5.1.0)

    thank you OP

  4. Parvez says:

    Yes i also support to use date_default_timezone_set(‘Your Time Zone’);
    If you have full control over your server then you can change php.ini to locate your timezone.
    Thanks

It's Your Turn

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
--- The Management ---