Solved

detect if date/time is daylight savings time

Posted on 2004-03-31
4
475 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
ID: 10727902
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
ID: 10727913
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
ID: 10728216
Thanks!
0
 
LVL 5

Expert Comment

by:jerry_jeremiah
ID: 10731004
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ffmpeg - "rtsp://...... Operation not permitted" 4 86
tripleUp challenge 7 86
Trying to run powershell  in a batch file. How do I do this? 8 105
Making an alias 7 101
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.

791 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