Parse ConfigTime string into DateTime with today’s date, then convert it to EST using TimeZoneInfo.FindSystemTimeZoneById(“Eastern Standard Time”) and compare with current EST time. Example:
configDate = DateTime.Parse("7:00 AM")
configEST = TimeZoneInfo.ConvertTime(DateTime.Today.Add(configDate.TimeOfDay), estZone)`
If TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, estZone) < configEST Then ...
I don’t have studio available right now to test this but try this approach suggested by AI.
// Parse "7 AM" as DateTime (today, EST)
ConfigTimeEST = New DateTime(SysCurrentTimeEST.Year, SysCurrentTimeEST.Month, SysCurrentTimeEST.Day, 7, 0, 0)
// Get current time in UTC
SysCurrentTimeUTC = DateTime.UtcNow
// Convert to EST
SysCurrentTimeEST = TimeZoneInfo.ConvertTimeFromUtc(SysCurrentTimeUTC, TimeZoneInfo.FindSystemTimeZoneById("US Eastern Standard Time"))
// IF Condition
If SysCurrentTimeEST < ConfigTimeEST Then
// Do something
End If
ConfigEST = DateTime.Today.Add(DateTime.Parse(ConfigTime).TimeOfDay)
CurrentEST = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(“Eastern Standard Time”))
If CurrentEST < ConfigEST Then …
Since your ConfigTime is a string (e.g. “7 AM”), you can:
1 - Parse it to DateTime in EST:
estZone = TimeZoneInfo.FindSystemTimeZoneById(“Eastern Standard Time”)
configDate = TimeZoneInfo.ConvertTime(DateTime.Parse(ConfigTime), estZone)
2 - Get current system time converted to EST:
nowEst = TimeZoneInfo.ConvertTime(DateTime.Now, estZone)
3 - Compare:
If nowEst < configDate Then → do something
This way ConfigTime stays dynamic (7 AM, 5 AM, etc.), always evaluated in EST against current system time.