The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

Adjust Server Time

Last updated on:

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.


  1. David
    Permalink to comment#

    The preferred way for PHP5 and above is to use:


    A list of the possible values are here:

    • Greg
      Permalink to comment#

      My programmer stated he cannot adjust the time in the database for we have no provision to update config files on the server and the coding is already adjusted.
      any thoughts?
      The hosting provider will not adjust the server time.

    • bhavesh

      thanks David

  2. David Walsh
    Permalink to comment#

    Yep, definitely use date_default_timezone_set(‘mytimezone’);

  3. Martin
    Permalink to comment#

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


    (PHP 5 >= 5.1.0)

    thank you OP

  4. Parvez
    Permalink to comment#

    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.

  5. Syed Zain
    Permalink to comment#

    Great work… i love to read codes from this site.. and reading such content has become my new hobby now a days.. keep it up.

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed