I need to check whether lastdate is within 12hours from currdate

I need to check whether lastdate is within 12hours from currdate. Please suggest how to code it.

lastdate is a string variable
image

currdate is a datetime variable
image

For Example: if lastdate is 12/15/2023 15:19:30 and currdate is 12/15/2023 17:20:21, lastdate is within 3 hours from currentdatetime then my if condition should result in true. if lastdate is 12/15/2023 15:19:30 and currdate is 12/15/2023 20:20:21, lastdate is beyond 3 hours from currentdatetime then my if condition should result in false.

grafik

1 Like

@ppr suggestion is correct, but I think he missed that lastdate is a string…so you’ll need to convert it. Also, there’s no reason to assign Now to a variable.

(Now - DateTime.ParseExact(lastDate,"MM/dd/yyyy HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture))
2 Likes

thanks for the critical crosscheck

Conversion option 1 of many:
grafik

DateTime.Parse,ParseExact, Convert.ToDateTime

with the Hint that UTC baselining and Now should be critical checked. Maybe LastProcessinOn (we assume UTC) should be compared with an UTC.Now

grafik

1 Like

I. Hate. Time. Zones.

:smiley:

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