How do you define daylight saving time in VBA?

Which function will tell us if the date is in VBA in DST or not?

+3
source share
2 answers

For non current dates (DST 2007 +):

First, you need a function to find the number of specific weekdays per month:

Public Function NDow(Y As Integer, M As Integer, _
                N As Integer, DOW As Integer) As Date  

' Returns Date of Nth Day of the Week in Month  

NDow = DateSerial(Y, M, (8 - Weekday(DateSerial(Y, M, 1), _
              (DOW + 1) Mod 8)) + ((N - 1) * 7))  

End Function  

You can then check the DST day against the following function calls:

Fall: NDow (Year (new), 11, 1, 1)
Spring: NDow (Year (newdate), 3, 2, 1)

For current date:

Call the Windows API function GetTimeZoneInformation, and it will return an enumeration (integer) with status.

I have the code for this from the Excel Excel Chip Pearson website.

Pearson site

+5
source

, , ( ), script Chip Pearson. (2:00 3:00) ( 3:00 2:00) - , .

- Excel:

Dim dates As String
dates = "A1:A20"

For Each c In Worksheets("Sheet1").Range(dates).Cells
    If (IsDateWithinDST(c.Value)) Then
        c.Value = DateAdd("h", 1, c.Value)
    End If
Next

, , .

DST .

+4

Source: https://habr.com/ru/post/1697498/


All Articles