Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adjust date/time for GMT 2

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
Hello,

I am located in Canada, but my server is in the UK. What is the best way to adjust to GMT -7 hours?

Thus far, I am using:

$date = date('l F j, Y');

But of course, that is returning the time of the server in the UK.

Thanks for your help.

frozenpeas
 
Code:
$timezone = -7;
echo date('l F j, Y', time() + 3600*($timezone+date("I")));

Not sure about Daylightsavingstime in Canada, so you might wish to remove '+date("I")' from the above formula.

HTH, Sascha

cu, Sascha
 
use the php putenv:
Code:
putenv ('TZ=Europe/Amsterdam');

here is my database-design for making your own iso3166 timezone script:


I where considering releasing the phpcode too, but it's too time-consuming for me to extract the code, explain, etc.

it's very easy to make a basic timezone script..
1: let users register with country
2: add TZ field to user-table
3: when user logs in, check if TZ field is != NULL
a) if != null, use putenv("TZ=tz from db");
b) if == null, run natural join on user-table (country), iso3166 and TZ table..
b.1) if 1 row returned, set that as TZ
b.2) if > 1 row returned, show dropdown list of avail. tz
b.2.1) let user select tz and set that to usertable tz

ps. this will not affect the mysql timezone.. so you also need something to calculate the difference between server-time and current timezone set via TZ=..

you can do this in the query.. maybe another field: tz-diff is nice to have, so you dont have to run a $foo = $bar - $newbar; and then run $foo in the query.

I hope you get what I'm saying.

good luck!

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top