VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Returns the time offset for the current daylight saving. Ths is set to UK time so the dates and off

by Andy Henderson (4 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 4th July 2010
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Returns the time offset for the current daylight saving. Ths is set to UK time so the dates and offset are for GMT/BST - they are clearly

API Declarations



Add it to a handy module

Rate Returns the time offset for the current daylight saving. Ths is set to UK time so the dates and off



    Dim qd As Date
    
    Select Case DatePart("m", dt)
    
        Case 4, 5, 6, 7, 8, 9
            GMTOffSet = 1 ' april to september = BST
        Case 1, 2, 11, 12
            GMTOffSet = 0: Exit Function ' November to February = GMT
        Case 3
            qd = "31/03/" & DatePart("YYYY", dt)
            For n = 0 To 6 ' find last sunday in march
                If DatePart("w", qd) = vbSunday Then Exit For ' got our last sunday in the month
                qd = DateAdd("d", -1, qd)
            Next
            GMTOffSet = Sgn(1 + Sgn(DateDiff("d", qd, dt)))
            
        Case 10
            qd = "31/10/" & DatePart("YYYY", dt)
            For n = 0 To 6 ' find last sunday in march
                If DatePart("w", qd) = vbSunday Then Exit For ' got our last sunday in the month
                qd = DateAdd("d", -1, qd)
            Next
            If Sgn(1 + Sgn(DateDiff("d", qd, dt))) = 1 Then
                GMTOffSet = 0
            Else
                GMTOffSet = 1
            End If
            
        End Select
                
    
End Function


Download this snippet    Add to My Saved Code

Returns the time offset for the current daylight saving. Ths is set to UK time so the dates and off Comments

No comments have been posted about Returns the time offset for the current daylight saving. Ths is set to UK time so the dates and off. Why not be the first to post a comment about Returns the time offset for the current daylight saving. Ths is set to UK time so the dates and off.

Post your comment

Subject:
Message:
0/1000 characters