Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular DateTime question

I'm writing a service but I want to have config settings to make sure that the service does not run within a certain time window on one day of the week. eg Mondays between 17:00 and 19:00.

Is it possible to create a datetime that represents any monday so I can have one App config key for DontProcessStartTime and one for DontProcessEndTime with a values like "Monday 17:00" and "Monday 19:00"?

Otherwise I assume I'll have to have separate keys for the day and time for start and end of the time window.

Any thoughts?

thanks

like image 986
benwebdev Avatar asked Jun 23 '26 04:06

benwebdev


1 Answers

You could use a utility that will parse your weekday text into a System.DayOfWeek enumeration, example here. You can then use the Enum in a comparison against the DateTime.Now.DayOfWeek

like image 91
Lazarus Avatar answered Jun 24 '26 17:06

Lazarus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!