Recent Postings

Recent Comments


RSS2 feed


Most Popular Posts

Script timezone

Friday, 31st March 2006 11:24pm
When you share the same timezone as your server then timezone setting for your scripts is no issue but for most of us this is not normally the case and once in a while you have to cater for some timezone. Lately I have been tackling the issue of getting the correct time  zone. I had to make sure that the timestamp recorded in the MySql database showed time in a particular timezone.
Because the Php version involved is pre 5.1.* I could not just add:

date.timezone = Africa/Harare

for example to the php.ini file and make all scripts use that timezone as default.

Neither could I use:


and so the easiest option for me was to use:


I just had to make sure that I put this statement in an include file that was available throughout the whole site (or the particular pages that required date and time). This was all good and fine until I
realised that the timestamp recorded in the MySql table was that for the server and not the one for the set timezone. I traced this to the insert query which was using something like this:

..."name = '$strName',timestamp = now(),"...

It realised that the time taken for the 'timestamp = now()' statement was for the MySql server time which is not affected by the the "putenv" command and therefore  I changed the above to something like

$timestamp = date('Y-m-d H:i:s');
.."name = '$strName',timestamp = '$timestamp',"...

Now the date function gives the date and time from the timezone as set out in the "putenv" command.

Post a comment:



(required, but not published)


Notify me of follow-up comments via e-mail