@foxyshadis said:
return (year % 4
== 0 && year % 100 != 0 && year % 400 == 0); does the
job quite nicely in my experience. (You'll want to test that it's a number and not null first.) Or Date.isLeapYear().
Let year = 4
year % 4 == 0 (true)
year % 100 != 0 (true)
year % 400 == 4 != 0 (false)
Let year = 400
year % 4 == 0 (true)
year % 100 == 0 (false)
year % 400 == 0 (true)
Well, at least it doesn't get any false positives.
This code might work a bit better:
[code language="c#"]return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);[/code]