Detecting if Dayligh Saving Time within Access

Posted on 2009-04-30
Medium Priority
Last Modified: 2012-05-06
I have an Access database that creates iCalendar/vCalendar files.  The files are created correctly, but if Daylight Saving Time is in operation it adds an hour to the time when opened in Outlook.  

This was working fine, until the clocks went forward a few weeks ago.

Any ideas?
Question by:Andy Brown
  • 2
  • 2
LVL 11

Accepted Solution

SeanStrickland earned 2000 total points
ID: 24272485
Try this:
Public Function IsDST(ByVal dDate As Date) As Boolean
'* Copyright © 2005  Camarillo Technology Associates (CTAServices.com)
'* Updated for new DST guidelines 4/30/2009 by Sean Strickland
  Dim dStartDST As Date
  Dim dEndDST As Date
  Dim DaysTilSun As Long
  If Not IsDate(dDate) Then Exit Function
  If Year(dDate) = 1899 Then Exit Function
  '* 1899 means it's probably a time-only value, so just bail
  '* Figure out the DST start/end for the supplied year
  '  (Assume DST rules as of now - 4/30/2009)
  '* Figure out how many days after Mar 8, [Supplied Year] that Sunday occurs
  '   Then set when DST starts
  DaysTilSun = 8 - Weekday("March 8, " & CStr(Year(dDate)), vbSunday)
  If DaysTilSun = 7 Then DaysTilSun = 0
  dStartDST = DateAdd("d", DaysTilSun, "March 8, " & CStr(Year(dDate)))
  '* Figure out how many days before Nov 1, [Supplied Year] that Sunday occurs
  '   Then set when DST starts
  DaysTilSun = Weekday("November 1, " & CStr(Year(dDate)), vbSunday) - 1
  dEndDST = DateAdd("d", -DaysTilSun, "November 1, " & CStr(Year(dDate)))
  '* Note that ANYtime on the Sunday that DST starts is considered DST and
  '   ANYtime on the day it ends is considered ST
  IsDST = DateDiff("d", dDate, dStartDST) <= 0 And _
   DateDiff("d", dDate, dEndDST) > 0
End Function

Open in new window


Author Closing Comment

by:Andy Brown
ID: 31576549
Perfect - thank you - very much appreciated.

Just out of curiosity, if I had a client in another part of the World (we are in the UK), would I to run any other checks?

LVL 11

Expert Comment

ID: 24272957
Yeah.  The only bad thing about this function is that it has to use static start/end dates for DST.  I'm honestly not sure how you would set it up for clients that span multiple regions with different DST start/end dates.  I would assume that you would need a table somewhere that defined where each client was located and have logic built into the function to support that.

Author Comment

by:Andy Brown
ID: 24272989
What a pain.  Thanks for all of your help on this.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

840 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