I am facing the problem to know if DateTime is between a date range in the dotnet.
For example if the x.SchedulerStart value is 2022-11-02 06:46:30
and x.SchedulerEnd value is 2022-11-02 23:26:30
. I want check this DateTime.Today value is inside the date range, but below coding is doesn't work. I have look at this StackOverflow question still cannot work How to know if a DateTime is between a DateRange in C#
Below is my coding:
x.SchedulerStart.Date >= DateTime.Today && x.SchedulerEnd.Date <= DateTime.Today
Whole code:
List<SAASMsgSchedulerForQueueList> msgSchedulerList = await _saasdbContext.SaMsgScheduler.AsNoTracking().Where(x => (x.Enabled == true && x.SchedulerStart.Date >= DateTime.Today && x.SchedulerEnd.Date <= DateTime.Today) &&
((x.SchedulerRecurring == "Daily" && x.RecurringTime == currentTime) || (x.SchedulerRecurring == "Weekly" && x.RecurringWeekday == weekDayNumber && x.RecurringTime == currentTime) ||
(x.SchedulerRecurring == "Monthly" && x.RecurringDay == currentDay && x.RecurringTime == currentTime) || (x.SchedulerRecurring == "Yearly" && x.RecurringMonth == currentMonth && x.RecurringTime == currentTime)))
.Join(_saasdbContext.TnMsgTemplate.AsNoTracking(),
schedule => schedule.TemplateId,
template => template.Id,
(schedule, template) => new { schedule, template })
.Join(_saasdbContext.SaMsgQuery.AsNoTracking(),
schedule => schedule.template.QueryId,
query => query.Id,
(schedule, query) => new SAASMsgSchedulerForQueueList()
{
ID = schedule.schedule.Id,
BranchID = schedule.schedule.BranchId,
TemplateID = schedule.schedule.TemplateId,
TemplateContent = schedule.template.TemplateContent,
Query = query.QuerySql,
MessageType = schedule.schedule.MessageType,
RecurringDatetime = schedule.schedule.RecurringDatetime,
}).ToListAsync();
Hope some one can guide me on how to solve this problems. Thanks.