How to convert String Value to EST time?

Hi Team,

My Variable ConfigTime= “7 AM”

I want to make this string as EST time variable value should remail same 7 AM

Current SystemTime

TimeZoneInfo.ConvertTimeToUtc(DateTime.Now)

for Example gives me 09/17/2025 04:33: 32 PM

then I want to check

If SysCurrentTime < ConfigTime //(7 AM)

Suggest me how.

Thanks in Advance!!!

@Sanket_Shinde1,

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 ...

7 AM should be dynamic
next time will be 5 AM

This values are already passing considering the EST time

just need to check with current SystemTime as i mentioned above.

Variable value 7 AM should be same after converting to EST

@Sanket_Shinde1

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

ConfigTime is not fix
It will be anything

Can you try this:

ConfigEST = DateTime.Today.Add(DateTime.Parse(ConfigTime).TimeOfDay)
CurrentEST = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(“Eastern Standard Time”))
If CurrentEST < ConfigEST Then …

@Sanket_Shinde1

if your current date is est then there is no conversion needed

ideally you need to compare the times only

you can get hours minutes etc separately..you might need to fix the format of input

for example if you want to compare only hours like afte 7 AM or 1 PM then you can give & or 13 as input and compare with datetime.now.hour

if you want to give minutes can give them also

cheers

@Sanket_Shinde1,

You can convert your dynamic date time string to datetime data type using tryparseexact function.

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.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.