I need to run a job/scheduler, which should only update records in database it is falling under the specified time range. In my case, the time range is from 3.30 AM to next day 1.30AM. So, with in this time frame the job needs to update the records. In order to get this time interval, I using TimeOfDay() function, but my logic is getting failed, bcoz if the currenttime is say 6.00 Am, then “currentTime <= todaysJob.ENDTIME.Value.TimeOfDay” is returning false. I am using the below code to check
var currentTime = DateTime.Now.TimeOfDay;
if (currentTime > todaysJob.STARTTIME.Value.TimeOfDay &&
currentTime <= todaysJob.ENDTIME.Value.TimeOfDay)
{
// Do logic
}
EDIT
So I added:
Start and End are equal to todaysJob.STARTTIME and todaysJob.ENDTIME, so you take them from DB as they are.
EDIT
If you could have your job like this:
then you could
EDIT
I’ve edited my code another time: added a method to avoid problems with the DayOfWeek enum