I loop through on my Razor page and turn the displayed row Tan if it meets the criteria of "Today". How do I test to see if the date falls inside of "This Week"? I know it has something to do with the "Between" syntax of "AddDays" but I can't seem to get it.
@foreach (var item in Model.Dances_Moderated)
{
DateStuff obj = new DateStuff();
var varNextEvent = obj.fNextEvent(item.RecurYesNo, item.SingleDate, item.RecurWeekOfMonth, item.RecurDayOfWeek);
string bgcolor = "Transparent";
@if (varNextEvent.Equals(DateTime.Today.ToShortDateString()))
{
bgcolor = "tan";
}
EDIT
I guess I was looking for a simple syntax built on the
@if (varNextEvent.Equals(DateTime.Today.ToShortDateString()))
But it won't take this:
if(varNextEvent => DateTime.Today.ToShortDateString()) && (varNextEvent <= DateTime.Today.AddDays(6).ToShortDateString())
Just a simple "Between" used in many other languages. "More than today and Less than 7 days from now". But I keep getting this error:
Operator '>='(and '<=') cannot be applied to operands of type DateTime and string
Only operator I am given is .Equals
.
If worse comes to worse I can just put 7 if statements and using .AddDays(n) I will just add one for each one:
@if (varNextEvent.Equals(DateTime.Today.AddDays(0).ToShortDateString()))
{
bgcolor = "tan";
}
@else if (varNextEvent.Equals(DateTime.Today.AddDays(1).ToShortDateString()))
{
bgcolor = "tan";
}
@else if (varNextEvent.Equals(DateTime.Today.AddDays(2).ToShortDateString()))
{
bgcolor = "tan";
}
Man, whoever invented this stuff never used it.