DateTime.Today.Month
has a return type of int
, but you’re checking against a char
value type. This check also returns true everytime as every month value is less than 12 or greater than 6 months. Rewrite this to be:
int todayMonth = DateTime.Today.Month;
if(todayMonth >= 6 && todayMonth <= 12)
Edit: To check if the date is between 12/1 and 6/30, you can try the following (thanks to @RoyCohen):
DateTime today = DateTime.Today;
if (today.Month >= 12 || today.Month <= 6)
{
Console.WriteLine("Pass");
}
7
solved c#: how to check date falls between Dec to Jun? [closed]