Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Daylight Savings Time

Status
Not open for further replies.

drost

Programmer
Mar 28, 2001
23
US
I'm coding something that needs to change GMT to local time. Since Daylight Savings Time starts on the first Sunday in April and ends on the last Sunday in October, how can I determine if the date is within Daylight Savings Time?

Thanks,

drost
 
You also need to know where you are. States like Arizona don't use daylight savings time, and countries in Europe go to DST on dates other than the first Sunday in April.

You can call a Win32 API function to find out this info.
[tt]
Public 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

Public Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Public Declare Function GetTimeZoneInformation Lib "kernel32" Alias "GetTimeZoneInformation" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
[/tt]

After calling the GetTimeZoneInformation function, examine the DaylightDate structure to find out when the change to daylight savings begins, and examine the StandardDate structure to find out when the change from daylight savings begins.

Hope this helps.

Chip H.

 
Thanks, Chip...

Is it possible to pass a date to the GetTimeZoneInformation function and then look at the DaylightName structure to see if that date was within Daylight Savings Time? I can only seem to get it to return the current time.

Thanks!
 
The GetTimeZoneInformation call will only tell you when daylight savings time begins and ends. You'll need to do a call to DateDiff to see if your date falls into that range (a negative result might mean you're on standard time).

You'll have to reformat the SYSTEMTIME structure into a normal VB Date datatype variable first, of course.

Chip H.
 
Thanks, Chip...This was a big help!

Dave
 
You didn't say exactly what your program was doing but if it's getting GMT/UTC from a time service to set your local clock there is an easy way without having to use timezone or daylight corrections:
Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
Also broadcast this to Windows so the system tray clock gets updated immediately using:
SendMessage HWND_TOPMOST, WM_TIMECHANGE, 0&, ByVal 0
If you need more info send an e-mail:(dgs@natallink.com.br).
 
how do you properly call the function? I can't seem to get my brain around this trivial function...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top