473,378 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

MySQL timezone support - setting from PHP

I am using the MySQL date and time functions and they save a lot
of my time. But the server is located in a time zone 2 hours
away. I read in the SQL docs how to set the timezone on a
per-connection basis, but how would I do that from PHP ?

bill
Oct 14 '07 #1
4 8393
On Sun, 14 Oct 2007 20:54:40 +0200, bill <no****@spamcop.netwrote:
I am using the MySQL date and time functions and they save a lot of my
time. But the server is located in a time zone 2 hours away. I read in
the SQL docs how to set the timezone on a per-connection basis, but how
would I do that from PHP ?
Untested:
mysql_query('SET time_zone = timezone_name');

Where the MySQL manual states:
timezone values can be given in several formats, none of which are case
sensitive:
1. The value 'SYSTEM' indicates that the time zone should be the same as
the system time zone.
2. The value can be given as a string indicating an offset from UTC, such
as '+10:00' or '-6:00'.
3. The value can be given as a named time zone, such as 'Europe/Helsinki',
'US/Eastern', or 'MET'. Named time zones can be used only if the time zone
information tables in the mysql database have been created and populated..

Ideally, you could use:
mysql_query("SET time_zone = '".date_default_timezone_get()."'");

--
Rik Wasmus
Oct 14 '07 #2
Rik Wasmus wrote:
On Sun, 14 Oct 2007 20:54:40 +0200, bill <no****@spamcop.netwrote:
>I am using the MySQL date and time functions and they save a lot of my
time. But the server is located in a time zone 2 hours away. I read
in the SQL docs how to set the timezone on a per-connection basis, but
how would I do that from PHP ?

Untested:
mysql_query('SET time_zone = timezone_name');

Where the MySQL manual states:
timezone values can be given in several formats, none of which are case
sensitive:
1. The value 'SYSTEM' indicates that the time zone should be the same as
the system time zone.
2. The value can be given as a string indicating an offset from UTC,
such as '+10:00' or '-6:00'.
3. The value can be given as a named time zone, such as
'Europe/Helsinki', 'US/Eastern', or 'MET'. Named time zones can be used
only if the time zone information tables in the mysql database have been
created and populated.

Ideally, you could use:
mysql_query("SET time_zone = '".date_default_timezone_get()."'");
Thanks RIK, I haven't had time to test it yet, I'll let you know.

bill
Oct 16 '07 #3
On Oct 14, 3:10 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
On Sun, 14 Oct 2007 20:54:40 +0200, bill <nob...@spamcop.netwrote:
I am using the MySQL date and time functions and they save a lot of my
time. But the server is located in a time zone 2 hours away. I read in
the SQL docs how to set the timezone on a per-connection basis, but how
would I do that from PHP ?

Untested:
mysql_query('SET time_zone = timezone_name');
tested mysql_query('SET time_zone = US/Eastern');
result: no error, no change at all.
datetime is still two hours off.

Oct 20 '07 #4
bill wrote:
On Oct 14, 3:10 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.comwrote:
>On Sun, 14 Oct 2007 20:54:40 +0200, bill <nob...@spamcop.netwrote:
>>I am using the MySQL date and time functions and they save a lot of my
time. But the server is located in a time zone 2 hours away. I read in
the SQL docs how to set the timezone on a per-connection basis, but how
would I do that from PHP ?
Untested:
mysql_query('SET time_zone = timezone_name');

tested mysql_query('SET time_zone = US/Eastern');
result: no error, no change at all.
datetime is still two hours off.
correction, time is still one hour off - no change.
(it is too early to read an analog clock)
bill
Oct 20 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bob | last post by:
I am sure this has been answered in over whelming detail in this group, however the search results have not turned up any thing I am interested in. I want a simple form generator in PHP that...
2
by: john | last post by:
How does one set the timezone on an sql server? I am in the uk and using a mysql server in finland and would like to set the timezone to gmt. thx
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
4
by: Dan Lewis | last post by:
I've imported a ms access database into a table in a mysql database. The access database contains a field that holds date/time values in 'general date' format. These all show up at 01/01/1970 in...
0
by: jrhastings | last post by:
I know there are many threads on this topic but I haven't yet found an answer to this question. I'd like to map from a utc to a local time in an arbitrary timezone (not necessary the default local...
2
by: ojorus | last post by:
Hi! A simple question maybe... I have a datetime column in a table, and want to automaticly insert local (Norwegian) time into the column. (I use PHP 5) I can not use NOW() since the mysql...
0
by: helloitsme | last post by:
Hello All! I know there already exists a thread with this topic by Mike! But my problem did not get solved with that.... I have a working code in VB6 that can set the selected timezone for the...
13
by: Richard Brooks | last post by:
Does anyone here open a second MySQL database and use that as a straight IDX type file that points to the record number in the main database, for speed's sake? Some time ago I'd set up a...
6
by: jehugaleahsa | last post by:
Hello: I would like it so that the time displayed was always for CDT/CDS. Potentially, the application can be run at locations in Mountain Time or Central Time. This is what I have now: //...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.