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.


  1. User Avatar
    Permalink to comment#

    The preferred way for PHP5 and above is to use:


    A list of the possible values are here:

  2. User Avatar
    David Walsh
    Permalink to comment#

    Yep, definitely use date_default_timezone_set(‘mytimezone’);

  3. User Avatar
    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. User Avatar
    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. User Avatar
    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!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.