I think that any answer, including adding hours at midnight or adding time in excess of an hour, is probably doomed to fail at some point due to daylight saving time.
Dim dtToCheck As DateTime = "3/13/2011 00:12"
Dim tz As TimeZone = System.TimeZone.CurrentTimeZone
Dim dl As System.Globalization.DaylightTime = tz.GetDaylightChanges(dtToCheck.Year)
Dim dt As DateTime = Format(dtToCheck, "yyyy-MM-dd HH:00:00.000")
If dt < dtToCheck Then dt = dt.AddHours(1)
Do Until dt.Hour = 2
If dt < dl.Start And dt.AddHours(1) >= dl.Start Then
'will go over
dt = dt.Add(dl.Delta)
End If
dt = dt.AddHours(1)
Loop
TextBox2.Text = dt
On March 13,2011 at midnight the following 2: AM - March 14th, at least in my time zone.
source
share