Skip navigation
15852 Views 8 Replies Latest reply: Mar 28, 2010 2:41 PM by David Birmingham RSS
Scott Nicholson New Enzee 6 posts since
Feb 5, 2010
Currently Being Moderated

Mar 21, 2010 9:48 PM

Dealing with time changes from daylight savings

Hi-


I've searched around for a solution to this and have come up empty. How do you deal with the effect of daylight saving in your queries that involve a time-zone shift? I'm hoping to find a solution like MySQL where you can set a time_zone session and have it apply to all subsequent references to time in your queries.

 

For example, in Netezza, I may want count(*) for today, where the time zone is PST:

 

select count(*) from mytable where date(data_ts - interval '8 hour') = date(now() - interval '8 hour');

 

Of course this works fine, but with the recent change, I should replace the 8 with a 7.

 

Is there a way to do this without replacing this in all of my queries?? This seems straightforward, but I'm unsure if this is possible with Netezza.

 

Thanks!

-Scott

  • David Shuttleworth Active Enzee 270 posts since
    May 14, 2008

    I'm wondering if anyone has written a UDF to handle this? but even if this was done, it would still require a change to your SQL queries to incorporate the UDF.

     

    How many timezones do you have to cope with? If it's not for the general case, but only a few specific timezones, it should be relatively easy to either code some sort of case statement or where clause, or maybe use a lookup table which defines the rigth offset for the dates or date ranges.

     

    But any of these approaches will need a change to the SQL example you gave..

     

    D.

  • ddas New Enzee 11 posts since
    May 22, 2006

    We have created a lookup table and use a case statement to handle Daylight saving. The best solution is to write a UDF and I was hoiping that someone might have created one already but last time I posted the similar question,I did not hear from anyone. I think Netezza should provide this with their SQL add-ons.

  • David Birmingham Active Enzee 426 posts since
    Sep 24, 2007

    In a broader context, some of this is locale-oriented. For example, the UK has daylight savings, but not on the same boundaries as the US. Arizona doesn't do daylight savings at all. Some townships nationwide have opted out of daylight savings. There is a time zone standard in the US of Eastern Standard Time and Eastern Daylight Time etc.

     

    It is also important to keep in mind that no one group is responsible for owning the time-zone lines or standards. These are generally agreed upon but not standardized in the same sense as currency and other regulated domains. Alaska for example is all-inside the international date line not because of geography, but because everyone thinks they should be, and so they are. The IDL is actually drawn-around Alaska on the map.

     

    Many enterprises solve their time zone and time/date issues with a time dimension entity as a one-stop shop, containing all business holidays/bank holidays, designating weekends, quarters, sales and business periods etc. along with the designations for time zones and countries, hourly offsets and the like. This is usually very site/enterprise-specific.

     

    And in case people have been asleep, global enterprises are moving away from nightly processing and are instead using time-zone offsets. This means that when the Hong-Kong markets close, their processes start kicking in while the UK markets are still open, likewise when UK markets close it is 5 hours before the USA markets close, and the UK folks want their data. So the whole idea of a nightly process is washed away in favor of processing "as the world turns" (and all the daytime drama that goes with it)

  • Mike Macievich New Enzee 1 posts since
    Mar 17, 2010

    I agree.  From my experience, though, using a lookup table with the dates and offsets is the best approach  - this can then be incorporated in the ETL and the converted local times can be stored (you can, of course, do the conversions on the fly, but this extra processing (esp if using a BI tool that will generate multi-pass SQL (we were using MSTR)) slowed things quite a bit. 

     

    This project required a conversion of their data (all timestamps were in UTC) to the local time (the client had facilities around the world) - the problem was that each locale had a different offset (of course), and a different date (and even time of day) as to when DST would happen (and this would change from year to year).  Because there were so many variables, having all of the conversions contained within case statements was just too bulky and difficult to manage; instead, I created a lookup table with the DST timestamp associated w/ each locale, then the appropriate hour offset - this would then be added or substracted from the actual data as need to derive the local time.

     

    Since you are only converting to PST, this may be overkill for you; however, I suggest you check the dates and times for prior DST dates (if you have historical data) and future ones so that you don't hard code logic that may incorrect in future years.  If the dates going forward are all over the map, then storing all this in a lookup table may be the cleaner (and more maintainable) approach.

     

    Hope this helps.

  • David Birmingham Active Enzee 426 posts since
    Sep 24, 2007

    This would imply that not only does the time zone need to be data driven, it also needs to be responsive to dynamic changes from bored world leaders, or at least those leaders with too much time on their hands, per the article.

     

    What if Greenwich Mean Time did something really mean?

     

    This just underscores the necessity for it being (meta)data-driven and reasonably dynamic - because there is no clearinghouse or regulatory commission for global time.

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points