Marius Vasile

Marius Vasile

  • 587
  • 1.9k
  • 149.3k

C# using DateTime Year in an if condition

Feb 4 2023 3:36 PM

I am trying to add to an if condition current year

DateTime nowDate = DateTime.Today;

  if (ProgCMP != null && ProgCMP.ProgDate.Year == nowDate.Year)
  {
      HaveDataProg = true;
  }

I know ProgCMP.ProgDate.Year is 2023, I got it listed from model but I failed getting the year of current date to make the comparison. What shoukld be the approach, please


Answers (2)