Results 1 to 23 of 23

Thread: GetTimeZoneInformation Issue

Hybrid View

  1. #1
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: GetTimeZoneInformation Issue

    in an application i have been using buggy code for 4 years, without realising till this thread, mostly the time difference was correct, if it was out of sync for a week at the time of daylight saving change, i never noticed

    still it is better to have the code working correctly
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  2. #2

    Thread Starter
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    Re: GetTimeZoneInformation Issue

    Quote Originally Posted by westconn1 View Post
    in an application i have been using buggy code for 4 years, without realising till this thread, mostly the time difference was correct, if it was out of sync for a week at the time of daylight saving change, i never noticed

    still it is better to have the code working correctly
    Hello westconn, I was in the exact same situation. I had some users complain and that was how I found out. You are correct certain daylight savings time change dates were 1 week off. I have an option in the application for a manual adjustment which is what I told the users to do during that one week.

    I tried your code but got incorrect results. I recreated the function format from vbnet but inserted your code. This is what it looks like:

    Code:
    Private Function GetTimezoneChangeDate(tziDate As SYSTEMTIME, _
                                           ByVal tziYear As Long, _
                                           ByVal dwType As DateFormats) As String
    
      'thanks to Mathias Schiffer for this routine
      
       Dim tmp As Date
       Dim MonthFirstWeekday As Long
       Dim fday As Integer
       Dim j As Integer
    
       With tziDate
    
          Dim iFirstDay As Integer
          Dim iDay As Integer
          Dim lday As Integer
    
            fday = Weekday(DateSerial(tziYear, .wMonth, 1))
            j = (.wDayOfWeek - 1) * 7 + (2 - fday) + iDay
            If j < 1 Then j = j + 7  ' fixed here
            tmp = DateSerial(tziYear, .wMonth, j)
              '*********** fred zone code
                  iFirstDay = Weekday(DateSerial(tziYear, .wMonth, 1))
                  lday = iDay + 1
                  If iFirstDay > 0 Then lday = 9 - iFirstDay
                  lday = lday + (7 * (iDay - 1))
                  GetTimezoneChangeDate = DateSerial(tziYear, .wMonth, iDay)
                 ' *************
    
       End With
       
      'Now that the date has been calculated,
      'return it in the string format requested
      'In VB6, you can use the FormatDateTime
      'function to return date in specified format
       GetTimezoneChangeDate = Format$(tmp, "MMMM dd")
       
    End Function

Posting Permissions

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



Click Here to Expand Forum to Full Width