Hi all.
I have a problem with DateUtils.AddPeriod and DST which is In the USA today November, 7 2021
Here is my code
I attached a small project so you can try yourself.
My question is - why if I add 1 hour to 11/7/2021 12:00 AM - my code returns 11/7/2021 1:00 AM. If I add 1 hour to 11/7/2021 1:00 AM - my code returns 11/7/2021 1:00 AM and if I add 1 hour to 11/7/2021 2:00 AM - my code returns 11/7/2021 3:00 AM.
Is it because DST changes on 11/7/2021 at 2:00 AM?
But if I add not 1 but 2 hours
11/7/2021 12:00 AM returns 11/7/2021 1:00 AM
11/7/2021 1:00 AM returns 11/7/2021 2:00 AM
11/7/2021 2:00 AM returns 11/7/2021 4:00 AM
Thanks.
I have a problem with DateUtils.AddPeriod and DST which is In the USA today November, 7 2021
Here is my code
Add 1 hour:
Private Sub GetStrTo(strFrom As String, AddHour As Int) As String
Try
Dim Arr() As String
Dim NotTimeDate As String,NoteTimeStr As String
Dim P As Period
Dim Tick As Long ,NewTick As Long
Dim strTo As String
P.Hours=AddHour
Arr=Regex.Split(" ", strFrom)
NotTimeDate=Arr(0)
NoteTimeStr=Arr(1) & " " & Arr(2)
strFrom=NoteTimeStr
Tick=DateTime.DateTimeParse(NotTimeDate,NoteTimeStr)
NewTick=DateUtils.AddPeriod(Tick,P)
strTo=DateUtils.TicksToString(NewTick)
Return strTo
Catch
Log("GetStrTo " & LastException.Message)
Return "Error"
End Try
End Sub
End Sub
I attached a small project so you can try yourself.
My question is - why if I add 1 hour to 11/7/2021 12:00 AM - my code returns 11/7/2021 1:00 AM. If I add 1 hour to 11/7/2021 1:00 AM - my code returns 11/7/2021 1:00 AM and if I add 1 hour to 11/7/2021 2:00 AM - my code returns 11/7/2021 3:00 AM.
Is it because DST changes on 11/7/2021 at 2:00 AM?
But if I add not 1 but 2 hours
11/7/2021 12:00 AM returns 11/7/2021 1:00 AM
11/7/2021 1:00 AM returns 11/7/2021 2:00 AM
11/7/2021 2:00 AM returns 11/7/2021 4:00 AM
Thanks.