If you're looking for our "local date" PHP script, here it is...

  • Makes an adjustment between server time and local time
  • Nice and simple to use!
  • Only 4 lines required, commented lines can be removed
  • Works in older versions of PHP (v3+)

This script is useful if you use a virtual hosting service for your web pages. In our case, the server we use (at Pair Networks) is in Pittsburgh, USA, while our business is located in Victoria, Australia.

If you're using this on just one page or template section, just include the script within the php code and place the print line of code where you want the date to appear. Keep the four lines of code in their order, but there is no need to have them appear on four consecutive lines. By adding other $melbdate type variables, you could even have more than one date format display on the page.

If you're using this script on a number of pages, consider having it as an 'include' so that any changes only have to be made to the script only once on your server. In reality, you could delete all of the comment lines (save for the copyright and version lines!) and you'd only have a short easy 4 line script!

Limitation: in this version, there is no automatic allowance for your local daylight saving time. Thus, the difference in hours needs to be manually updated when daylight saving time starts/ends (if it is observed where you are). That is why I suggest you make it an include, and only have one copy you need to update throughout your website.


For PHP tutorials, start at www.php.net's links page. If you want to change the date format, see the options at: www.php.net/manual/function.date.php

Here is the script. The time difference here is "14", which is the difference between my local time and the server time during our (Australian) "standard" non-daylight savings time. When we change over to daylight savings time -- late October -- I manually adjust this time to be "16". So here it is:


// melbdate.php3
// rename file extension from .txt to .php3 or to .php

// Script copyright (C) 2000 Dean Kennedy, Terrabyte Communications
// Version 1.03 04 June 2006
// Free to use, modify and copy. You can safely delete all other
// commented lines and just leave the four line script

// Distributed under the terms of the GNU General Public License (GPL).
// There is NO WARRANTY, it is provided AS IS. Use it at your own risk.
// http://www.gnu.org/copyleft/gpl.html

// To adjust the format of the date, see www.php.net/manual/function.date.php
// If your local time is *behind* the server time, then change the "+" to
// a "-" in the $melbdate line
// If you don't know how many hours, then "uncomment" the three lines
// below by deleting "// " to see what the server time is (remember to
// put the comments "// " back when you've finished checking:
// $serverdate = date("l, d F Y h:i a");
// print ("$serverdate");
// print (" &nbsp; <p>");

// Variable for hours
$hourdiff = "14"; // hours difference between server time and local time

// Nothing needs to be changed below here unless you want to change
// the format of the date (see above for URL of options) or your local
// time is behind the server time

$timeadjust = ($hourdiff * 3600);
$melbdate = date("l, d F Y h:i a",time() + $timeadjust);
print ("$melbdate");


Here's a mini 3-line version of the very same script:

$hourdiff = "14"; // hours diff btwn server and local time
$melbdate = date("l, d F Y h:i a",time() + ($hourdiff * 3600));
print ("$melbdate");

Wisebiz logo