Solved

detect if date/time is daylight savings time

Posted on 2004-03-31
4
465 Views
Last Modified: 2013-11-20
Hi,

Given the following datetime string "2004-03-30 13:09:28" I need to detect if it is PST or PDT?

Dalight Savings time:
Starts: First Sunday in April at 2 am local time
Ends: Last Sunday in October at 2 am local time

What I need to do is append PST or PDT accordingly.

Thanks,
Alex
0
Comment
Question by:astankovic
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
wayside earned 500 total points
Comment Utility
int startday = 1;
int endday = 31;

COleDateTime startDST(2004, 4, startday, 2, 0, 0);
COleDateTime endDST(2004, 10, endday, 2, 0, 0);

while (startDst.GetDayOfWeek() != 1) {
  startday++;
  startDST.SetDate(2004, 4, startday);
}

while (endDst.GetDayOfWeek() != 1) {
  endday--;
  endDST.SetDate(2004, 10, endday);
}

// now startDST and endDST contain the start and end dates of daylight savings time
COleDateTime testDate(2004, 6, 12, 12, 34, 56);

if (testDate >= startDST && testDate <= endDST) {
  printf("PDT");
}
else {
  printf("PST");
}
0
 
LVL 14

Expert Comment

by:wayside
Comment Utility
More generally, you would extract the year out of your test date and use that when building the dates for startDST and endDST.
0
 
LVL 4

Author Comment

by:astankovic
Comment Utility
Thanks!
0
 
LVL 5

Expert Comment

by:jerry_jeremiah
Comment Utility
Hello,

Those times you mention for DST are very specifically USA and Canada only - in fact it doesn't even really apply to all of the USA and Canada because Fort St. John, Charlie Lake, Taylor and Dawson Creek in British Columbia, Creston in the East Kootenays, and most of  Saskatchewan (except Denare Beach and Creighton) don't use daylight savings time at all.

Just to confuse things, the UK switches at one o'clock in the morning the last Sunday in March and two o'clock in the morning in October.  New Zealand did their switchover three weeks ago and Australia did their's the week after that.  Besides which, any region in the southern hemisphere that does daylight savings time does it at the opposite time of the year (Autumn here in New Zealand is in March/April)

Jerry
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now