C#C
C#4y ago
Yashogi

Compare Year and Datetime year

I need my year to be less than or equal to current year.
DateTime dt = new DateTime(2022, 10, 06); 
this is the way I set up my Date Time
public readonly int Year;
is what I have in my class and I throw this exception but get an error
if (year <= dt) {
           throw new ArgumentOutOfRangeException("The Year must be greater than or equal to the current date and time.");
          }
Was this page helpful?