Compare current time with a datetime variable (first day of current month at 8am local time))

Hello, I need to check if it is the first run of a process in any given month by comparing current time against a time stored in a variable. this process runs every hour for the first 7 working days, the first run is scheduled to start at 8am on the first day of any month. I have:

dtNow =
dtFirstRunTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)

the dtFirstRunTime returns the first day of the month with 00:00:00, how to revise it to give me 08:00:00 (am local time)?

or any better way to determine if it is the first run?

thank you so much in advance

You can use:
new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 8, 0, 0)
result will be:

1 Like

@pikorpa Thank you so much for your quick response!

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