Determining Daylight Savings

  • Thread starter Thread starter Mike D
  • Start date Start date
M

Mike D

I have an odd request. I have two forms with US timezone
maps - one for daylight savings and one without. I'd like
to be able to open up the correct map depending on whether
it's daylight saving or not.

I use Mike Kaplan's NowPlusTZBias for replication. Is
there a way of determining whether "today" is daylight
savings time or standard?

Thanks
Mike
 
If Date() Between [StartDateForDST] And [EndDateDST] Then
..... Today is DST
Else
.... Today is not DST
End If
 
Thanks...that works. Any way of having code check the
system clock to determine if it's daylight savings? I
really didn't want to go in and change the code each year.
-----Original Message-----
If Date() Between [StartDateForDST] And [EndDateDST] Then
..... Today is DST
Else
.... Today is not DST
End If

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


I have an odd request. I have two forms with US timezone
maps - one for daylight savings and one without. I'd like
to be able to open up the correct map depending on whether
it's daylight saving or not.

I use Mike Kaplan's NowPlusTZBias for replication. Is
there a way of determining whether "today" is daylight
savings time or standard?

Thanks
Mike


.
 
Two suggestions:

1. DST ends on the last Sunday in October. You can code for this. There's
a similar date for the strat of DST which you can also code for.

2. Create a setup form containing [StartDateForDST] And [EndDateDST]. And
then use this line of code:
If Date() Between Forms!MyForm![StartDateForDST] And
Forms!MyForm![EndDateDST] Then

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


Mike said:
Thanks...that works. Any way of having code check the
system clock to determine if it's daylight savings? I
really didn't want to go in and change the code each year.
-----Original Message-----
If Date() Between [StartDateForDST] And [EndDateDST] Then
..... Today is DST
Else
.... Today is not DST
End If

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


I have an odd request. I have two forms with US timezone
maps - one for daylight savings and one without. I'd like
to be able to open up the correct map depending on whether
it's daylight saving or not.

I use Mike Kaplan's NowPlusTZBias for replication. Is
there a way of determining whether "today" is daylight
savings time or standard?

Thanks
Mike


.
 
Hi,
Daylight savings starts on the last Sunday in October and Standard time starts on the 1st Sunday in April so...
Here's something that is **not tested**

Public Function IsDaylightSavings() As Boolean
Dim intLastSunday As Integer
Dim intFirstSunday As Integer
Dim dtDaySav As Date
Dim dtStandard As Date

'dayight savings is the last sunday in Oct
'get the day that the 31st is
intLastSunday = WeekDay(DateSerial(DatePart("yyyy", Date), 10, 31))

Select Case intLastSunday
Case 1
'this is it, the 31st is the last Sunday
dtDaySav = DateSerial(DatePart("yyyy", Date), 10, 31)
Case Else
'subtract the correct number of days from the 31st to get the Sunday
dtDaySav = DateSerial(DatePart("yyyy", Date), 10, 31 - 1 - intLastSunday)
End Select

'standard time begins on the 1st Sunday in April
'get the day that is the 1st of April
intFirstSunday = WeekDay(DateSerial(DatePart("yyyy", Date), 4, 1))
Select Case intFirstSunday
Case 1
'this is it, the 31st is the last Sunday
dtStandard = DateSerial(DatePart("yyyy", Date), 4, 1)
Case Else
'add the correct number of days from the 1st to get the Sunday
dtStandard = DateSerial(DatePart("yyyy", Date), 10, 1 + (8 - intLastSunday))
End Select

If Date < dtDaySav And Date > dtStandard Then
IsDaylightSavings = False
Else
IsDaylightSavings = True
End If

End Function

--
HTH
Dan Artuso, Access MVP


Mike said:
Thanks...that works. Any way of having code check the
system clock to determine if it's daylight savings? I
really didn't want to go in and change the code each year.
-----Original Message-----
If Date() Between [StartDateForDST] And [EndDateDST] Then
..... Today is DST
Else
.... Today is not DST
End If

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


I have an odd request. I have two forms with US timezone
maps - one for daylight savings and one without. I'd like
to be able to open up the correct map depending on whether
it's daylight saving or not.

I use Mike Kaplan's NowPlusTZBias for replication. Is
there a way of determining whether "today" is daylight
savings time or standard?

Thanks
Mike


.
 
Hi,
small correction:
'add the correct number of days from the 1st to get the Sunday
dtStandard = DateSerial(DatePart("yyyy", Date), 4, 1 + (8 - intLastSunday))

--
HTH
Dan Artuso, Access MVP


Dan Artuso said:
Hi,
Daylight savings starts on the last Sunday in October and Standard time starts on the 1st Sunday in April so...
Here's something that is **not tested**

Public Function IsDaylightSavings() As Boolean
Dim intLastSunday As Integer
Dim intFirstSunday As Integer
Dim dtDaySav As Date
Dim dtStandard As Date

'dayight savings is the last sunday in Oct
'get the day that the 31st is
intLastSunday = WeekDay(DateSerial(DatePart("yyyy", Date), 10, 31))

Select Case intLastSunday
Case 1
'this is it, the 31st is the last Sunday
dtDaySav = DateSerial(DatePart("yyyy", Date), 10, 31)
Case Else
'subtract the correct number of days from the 31st to get the Sunday
dtDaySav = DateSerial(DatePart("yyyy", Date), 10, 31 - 1 - intLastSunday)
End Select

'standard time begins on the 1st Sunday in April
'get the day that is the 1st of April
intFirstSunday = WeekDay(DateSerial(DatePart("yyyy", Date), 4, 1))
Select Case intFirstSunday
Case 1
'this is it, the 31st is the last Sunday
dtStandard = DateSerial(DatePart("yyyy", Date), 4, 1)
Case Else
'add the correct number of days from the 1st to get the Sunday
dtStandard = DateSerial(DatePart("yyyy", Date), 10, 1 + (8 - intLastSunday))
End Select

If Date < dtDaySav And Date > dtStandard Then
IsDaylightSavings = False
Else
IsDaylightSavings = True
End If

End Function

--
HTH
Dan Artuso, Access MVP


Mike said:
Thanks...that works. Any way of having code check the
system clock to determine if it's daylight savings? I
really didn't want to go in and change the code each year.
-----Original Message-----
If Date() Between [StartDateForDST] And [EndDateDST] Then
..... Today is DST
Else
.... Today is not DST
End If

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com


I have an odd request. I have two forms with US timezone
maps - one for daylight savings and one without. I'd like
to be able to open up the correct map depending on whether
it's daylight saving or not.

I use Mike Kaplan's NowPlusTZBias for replication. Is
there a way of determining whether "today" is daylight
savings time or standard?

Thanks
Mike


.
 
Hi Mike

You can use a call to the GetTimeZoneInformation API:

========= start code =========
Option Explicit

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(0 To 63) As Byte ' Unicode string
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 63) As Byte ' Unicode string
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
Private Const TIME_ZONE_ID_UNKNOWN = 0
Private Const TIME_ZONE_ID_STANDARD = 1
Private Const TIME_ZONE_ID_DAYLIGHT = 2

Private Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) _
As Long

Public Function AreWeInDST() As Boolean
Dim TZI As TIME_ZONE_INFORMATION
Dim lRetVal As Long, s1 As String, s2 As String
lRetVal = GetTimeZoneInformation(TZI)
If lRetVal = TIME_ZONE_ID_INVALID Then
MsgBox "Error getting TimeZone Info"
Else
AreWeInDST = lRetVal = TIME_ZONE_ID_DAYLIGHT
' you can extract other info from the TZI here,
' like, for example the timezone name and the
' bias from UTC
End If
End Function
=============== end code ============
 
Worked like a charm Graham....thanks!!
Mike
-----Original Message-----
Hi Mike

You can use a call to the GetTimeZoneInformation API:

========= start code =========
Option Explicit

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(0 To 63) As Byte ' Unicode string
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(0 To 63) As Byte ' Unicode string
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Const TIME_ZONE_ID_INVALID = &HFFFFFFFF
Private Const TIME_ZONE_ID_UNKNOWN = 0
Private Const TIME_ZONE_ID_STANDARD = 1
Private Const TIME_ZONE_ID_DAYLIGHT = 2

Private Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) _
As Long

Public Function AreWeInDST() As Boolean
Dim TZI As TIME_ZONE_INFORMATION
Dim lRetVal As Long, s1 As String, s2 As String
lRetVal = GetTimeZoneInformation(TZI)
If lRetVal = TIME_ZONE_ID_INVALID Then
MsgBox "Error getting TimeZone Info"
Else
AreWeInDST = lRetVal = TIME_ZONE_ID_DAYLIGHT
' you can extract other info from the TZI here,
' like, for example the timezone name and the
' bias from UTC
End If
End Function
=============== end code ============
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


I have an odd request. I have two forms with US timezone
maps - one for daylight savings and one without. I'd like
to be able to open up the correct map depending on whether
it's daylight saving or not.

I use Mike Kaplan's NowPlusTZBias for replication. Is
there a way of determining whether "today" is daylight
savings time or standard?

Thanks
Mike


.
 
Back
Top