2

Suppose we have to save Norwegian time 9:00 If we are ignoring day light.In database in UTC we will save 8:00. In Display we will add +1 for Norway 9:00. In India we are adding +5:30 means 1:30 – it should be 12:30, 1 hour difference

If we consider day light then we should add user +2 for Norway Means in database we will save 7:00 And for Norway for +2 it will be 9:00 And for India it will be 12:30 – correct time. But in this case if we want to see old dates which we have added when day light was false with +1 But now if we show old dates by adding +2 hours. Then it will be 1 hour earlier.

MY Problem

What i am doing is getting local time entered by user.

and converting it to UTC by adding offset hour for user timezone.

And while getting i am passing offset hour for user timezone to SQL and in SQL i am converting UTC date to user local time.

and here the issue comes old dates which i have entered with +1 before 31 march.After 31 march as user offset will be +2 because of day light.So old dates shifted by one hour.

Please correct me where i am doing wrong in handling dates. And how can i solve my problem

Anuj Kumar
  • 21
  • 3
  • What does the data represent? If it's a log of when something occurred, it should be in UTC, and preferably translated before it hits the db. Query by translating user input first, display by translating output in the view layer. If it represents scheduling, it gets weird; what happens when DST changes (most people want the local time to stay the same, but what happens when the event is an international phone call?). Some RDBMSs (and application languages) have no/terrible support for timezones/dst, what are you using? – Clockwork-Muse Jun 14 '14 at 05:50
  • Hi, in My problem section i have written what i am doing.actually i am looking for solution how to show these dates.Which is the best way – Anuj Kumar Jun 16 '14 at 06:43
  • Your question still feels rather opaque to me. What do the dates represent? What are you storing? How are you querying? Don't just describe what you're doing, show some of the actual code you're using. – Clockwork-Muse Jun 16 '14 at 09:12
  • I have to agree with @Clockwork-Muse. Without a problem domain, it's virtually impossible to provide an acceptable answer to the question as-is. Take a look at the best practices for handling time zones and daylight savings here http://stackoverflow.com/questions/2532729/daylight-saving-time-and-time-zone-best-practices which provides a variety of solutions and all depending on how you plan to use the times, verses a one size fits all solution. – Sybeus Jul 03 '14 at 05:05

0 Answers0