Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Daylight savings time issues (VB6 SR2)

    Hi, I am having trouble with some daylight savings time issues and wondered if anyone had the answer.

    I found the GetTimeZoneInformation API and functions that use it. The main function returns the date/time with an offset time if the date is in daylight savings time. However, it works from the PC clock.

    I have a user specified date/time that I need to ammend if the specified date is in DST. Does anyone have some alternate code or an API that allows the date to be specified?

    Any help would be great thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Daylight savings time issues (VB6 SR2)

    You can use the GetTimeZoneInformation function to get the date/time that DST starts (the DaylightDate member of the TIME_ZONE_INFORMATION structure) and that DST ends (the StandardDate member).
    From these, you can calculate whether DST applies to a given date.
    You can also retrieve the info directly from the registry: the HKEY_LOCAL_MACHINESystemCurrentControlSetControlTi meZoneInformation key contains the following values:

    ActiveTimeBias is the currently active offset from GMT.
    Bias is the negative offset from GMT in seconds
    DaylightBias is the offset applied to StandardBias
    DaylightStart is the date/time when to switch to daylight time.
    DaylightName is the name for Daylight Time
    StandardBias is the offset applied to Bias
    StandardName is the name of the time zone
    StandardStart is the date/time when to switch back to standard time.

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Daylight savings time issues (VB6 SR2)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    Thanks for your reply Hans, however, I couldnt seem to get my head around the info returned from TIME_ZONE_INFORMATION and the registry.
    I ran the following in VB and although the results matched the info in the registry, I couldnt seem to work out where the date came from:
    Debug.Print tz.StandardDate.wDay
    Debug.Print tz.StandardDate.wMonth
    Debug.Print tz.StandardDate.wYear
    Debug.Print tz.StandardDate.wHour
    Debug.Print tz.StandardDate.wMinute
    Debug.Print tz.StandardDate.wSecond

    It returned 5 10 0 2 0 0. The 10 is the month and the 2 is the time, but i'm not sure how the day is derived from the 5. However, my search on the web returned some results from http://www.freevbcode.com/ShowCode.asp?ID=7094

    Olins code works fine, but i'm going to ammend it slightly for my needs as I dont agree with assuming the time is past 2am if no time was specified resulting in midnight 00:00:00 returning true on the day the time changes. I think most programmers are aware that 00:00:00 is used if no time is specified so I think that should be accounted for before calling this function, not in the function.

    If the answer to where day is derived from my attempt using TIME_ZONE_INFORMATION is only going to take a couple of moments to explain I still would like to know as it might be useful.

    Thanks again for your help Hans.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Daylight savings time issues (VB6 SR2)


  5. #5
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Daylight savings time issues (VB6 SR2)

    Excellent, thanks Hans. I'm not entirely sure my settings are right as on this basis:
    wHour = 2, wMonth = 10, wDayOfWeek = 4, wDay = 5.
    I should probably have a 4 in my DayOfWeek instead of the 0 that is currently there.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Daylight savings time issues (VB6 SR2)

    wHour = 2, wMonth = 10, wDayOfWeek = 4, wDay = 5 would mean 2 AM (hour = 2) on the last (day =5) Thursday (day of week = 4) in October (month = 4).
    The setting for most European countries is wDayOfWeek = 0, wDay = 5, wMonth = 10 for the last Sunday in October, and wDayOfWeek = 0, wDay = 5, wMonth = 3 for the last Sunday in March; in many states of the USA the latter is wDayOfWeek = 0, wDay = 1, wMonth = 4 for the first Sunday in April.

  7. #7
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Daylight savings time issues (VB6 SR2)

    Thanks for being my brain today Hans <img src=/S/hansv.gif border=0 alt=HansV width=27 height=26> , mine's at the back of my skull wrapped in a blanket with a runny nose. <img src=/S/sick.gif border=0 alt=sick width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •