Newbie - Time zone

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi guys :)

I need some help with several different issues, and I know that
there's someone (if not almost everyone :) who can help me :)

I was having some troubles with timezones (guess it's a common problem)
but I overrided it with something like:

--- code ---
$time_h = date ("H");
if ($time_h == "23") {
  $time_h = "00";
} else {
  $time_h = $time_h + 1;

$time_d = date("d");
if ($time_h == "00") {
  $time_d = $time_d + 1;
$date = $time_d. "/". date("m/Y");

echo $date;

if ($time_h >= "1" && $time_h <= "9") {
  $time = " 0". $time_h. ":". date("i:s");
} else {
  $time = " ". $time_h. ":". date("i:s");

echo $time;
--- /code ---

It's not neat as I know it could be...
But I simply couldn't find a batter way to change time to +1 zone :(

Someone has already done script or can shed some light?

Re: Newbie - Time zone

I think using Timestamps to work on date/time is easier. Consider the
following code.

function myDate(){
    /* add 1 day (3600 sec) to the current timestamp */
    $loc_time= time()+1*3600;
    /* Pass the new timestamp to date() (it will use it instead of
implicitely use the current timestamp) */
    $date = date('d/m/Y H:i:s', $loc_time);
    return $date;

echo myDate();


Quoted text here. Click to load it

Re: Newbie - Time zone

You might also want to check the localtime() function wich return an array
containing local date/time informations.


Quoted text here. Click to load it

Re: Newbie - Time zone

Add one HOUR not one day ...Anyway the code is the same, 3600 sec is 1 hour.
Quoted text here. Click to load it

Re: Newbie - Time zone

Quoted text here. Click to load it

Snipped code is horrible. It will fail horribly during changes from/to

Search for usage of the TZ enviroment variable. Only problem is knowing
what the next timezone is, eg:
$ cat foo.php

echo "It's ".date('r',$now)." over here.\n";

echo "It's ".date('r',$now)." over there.\n";
$ php4 ./foo.php
It's Tue,  7 Dec 2004 22:04:34 +0100 over here.
It's Tue,  7 Dec 2004 21:04:34 +0000 over there.

Here is 'CET', previous would be 'BST' and next defined as in Isreal.

Re: Newbie - Time zone

Quoted text here. Click to load it
Quoted text here. Click to load it

Correction: IST is nothing so UTC is returned.

Re: Newbie - Time zone

i use something like the following:

$serverdate = date("Y-m-d H:i:s", gmmktime() - (7*3600));
produces '2004-12-07 16:28:07' GMT - 0700.  change the  -(7*3600) in
accordance to your time zone.
+0300 is +(3*3600)
-0900 is -(9*3600)

Re: Newbie - Time zone

Carved in mystic runes upon the very living rock, the last words of Six
of comp.lang.php make plain:

Quoted text here. Click to load it

Skip all that and just use:


or whichever time zone is appropriate for you: /

Just be sure and use the -1. I know it's counterintuitive, as you want to
add an hour, but the -1 indicates the difference from you to UTC, not the
other way around.

All of PHP's date and time functions will reference that variable.

Alan Little
Phorm PHP Form Processor /

Re: Newbie - Time zone

-> Six ->
Quoted text here. Click to load it

Thank you all for your suggestion!
And yes, Daniel, that code of mine is horrible indeed :)

I tried Daedalus' suggestion and it worked perfectly, thank you :)

Alan, haven't tried 'putenv' yes, but I surely will as it seems a way
easier (why haven't I done it by now... don't ask :)

Site Timeline