Solved

detect if date/time is daylight savings time

Posted on 2004-03-31
4
482 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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