2
Answers

C# using DateTime Year in an if condition

Marius Vasile

Marius Vasile

2y
504
1

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)