C
C#3y 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);
DateTime dt = new DateTime(2022, 10, 06);
this is the way I set up my Date Time
public readonly int Year;
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.");
}
if (year <= dt) {
throw new ArgumentOutOfRangeException("The Year must be greater than or equal to the current date and time.");
}
8 Replies
pip
pip3y ago
can't you just do dt.Year? Iirc
Yashogi
YashogiOP3y ago
Umm Not sure because it's all sent back to the program error CS0019: Operator '<=' cannot be applied to operands of ty pe 'int' and 'DateTime' this is the error code i get
pip
pip3y ago
do dt.Year instead of dt if(year <= dt.Year)
Yashogi
YashogiOP3y ago
Ok I'll give it a shot thank s
pip
pip3y ago
You got it boss, that'll be $5,000. DM me for my Venmo
Yashogi
YashogiOP3y ago
LMFAO IT WORKED YO Rip Just started using dates and times thanks so much boss LMAOAOAOAO I was doing research for far too long fk this
pip
pip3y ago
you can inspect classes to find this stuff btw So highlight DateTime then right click, go to definition then you can see all of its properties very useful when working with new things/libraries
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server