473,408 Members | 2,052 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,408 software developers and data experts.

summer time issue in mysql

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 server is set up with a different time zone. So now i use
UTC_TIMESTAMP() + INTERVAL 2 HOUR, which give me the right time now. BUT a
problem will occur some time in october, when we end summer time, and Norway
will go back to UTC + 0100.
Of course I could manually go into my PHP code and change the query to ...
UTC_TIMESTAMP() + INTERVAL 1 HOUR ..., but I was hoping there was some
easier way to to this. (I don't want to change my code twice a year...).

One solution is of course to tell my PHP code when summer time starts and
ends for the next say ten years, and then vary the INTERVAL number from 1 to
2 or the other way. But still I was hoping there was some easier ways...

Any suggestions?

greetings
ojorus
Sep 26 '06 #1
2 1804

ojorus wrote:
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 server is set up with a different time zone. So now i use
UTC_TIMESTAMP() + INTERVAL 2 HOUR, which give me the right time now. BUT a
problem will occur some time in october, when we end summer time, and Norway
will go back to UTC + 0100.
Of course I could manually go into my PHP code and change the query to ...
UTC_TIMESTAMP() + INTERVAL 1 HOUR ..., but I was hoping there was some
easier way to to this. (I don't want to change my code twice a year...).

One solution is of course to tell my PHP code when summer time starts and
ends for the next say ten years, and then vary the INTERVAL number from 1 to
2 or the other way. But still I was hoping there was some easier ways...

Any suggestions?

greetings
ojorus
In PHP, call date_default_timezone_set() with the appropriate timezone
setting. Then use date() to format the UTC timestamp you get from
MySQL. No adding or deleting hours, no summer time, everything will
just take care of itself.

Sep 26 '06 #2

"ZeldorBlat" <ze********@gmail.comskrev i melding
news:11**********************@i3g2000cwc.googlegro ups.com...
>
ojorus wrote:
>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 server is set up with a different time zone. So now i use
UTC_TIMESTAMP() + INTERVAL 2 HOUR, which give me the right time now. BUT
a
problem will occur some time in october, when we end summer time, and
Norway
will go back to UTC + 0100.
Of course I could manually go into my PHP code and change the query to
...
UTC_TIMESTAMP() + INTERVAL 1 HOUR ..., but I was hoping there was some
easier way to to this. (I don't want to change my code twice a year...).

One solution is of course to tell my PHP code when summer time starts and
ends for the next say ten years, and then vary the INTERVAL number from 1
to
2 or the other way. But still I was hoping there was some easier ways...

Any suggestions?

greetings
ojorus

In PHP, call date_default_timezone_set() with the appropriate timezone
setting. Then use date() to format the UTC timestamp you get from
MySQL. No adding or deleting hours, no summer time, everything will
just take care of itself.
Problem is, I have PHP 5.0.4, which does not support
date_default_timezone_set(), so I have to do it another way.

ojorus
Sep 27 '06 #3

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

Similar topics

2
by: Marcus | last post by:
I am having some problems with trying to perform calculations on time fields. Say I have a start time and an end time, 1:00:00 and 2:30:00 (on a 24 hour scale, not 12). I want to find the...
20
by: Sims | last post by:
Hi, I have a field in my DB that saves the date/time as a integer. I get the time on my server using the time() function. now, moving away from php and looking at (My)SQL only. If I use...
0
by: Richard Jones | last post by:
Garbage Collection & Memory Management Summer School 20-21 July 2004, Canterbury, UK The performance of today's memory-hungry applications depends on efficient dynamic memory management,...
0
by: Ryan Schefke | last post by:
------=_NextPart_000_0077_01C34C8B.2B90C960 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit ..I just sent this out to the win32 distribution list but no one has...
0
by: Sara Price | last post by:
This year's XML Summer School is approaching once again and so it is time to make sure you register your place now! The event will again be held at Wadham College, University of Oxford, from...
1
by: Volkan Arslan | last post by:
------------------------------------------------------------- LASER Summer School on Software Engineering Practical Techniques of Software Quality Elba, Italy September 12 - 18, 2004 ...
6
by: ammd | last post by:
Hi, I installed Microsoft DirectX 9.0 SDK (Summer 2004) but when I create a project and try to add the necessary references I can't find them. Does anybody know where to look for them? BTW, I have VS...
0
by: Volkan Arslan | last post by:
------------------------------------------------------------- LASER Summer School on Software Engineering Software engineering for concurrent and real-time systems Elba, Italy September 11 -...
5
by: Dr J R Stockton | last post by:
Computed at <URL:http://www.merlyn.demon.co.uk/js-datex.htm#OSTby the code shown above it when using Opera 9.24 : Test exact dates in two 11-year ranges; IE & FF are OK. Opera 9.24 shows...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.