Here is a really stupid question. I am trying to determine if February has 29 days in it, I use this:
//MessageBox "It is February"
MessageBox "The year is " + newMortgageAmortizationProgramWindow.DateTimePicker1.SelectedDate.Year.ToString
if newMortgageAmortizationProgramWindow.DateTimePicker1.SelectedDate.Year mod 2 = 0 then
numberOfDaysInAMonth = 28
else
MessageBox "Leap Year"
numberOfDaysInAMonth = 29
end if
And no matter whether I use the DatePicker1.SelectedDate.Year or an actual number, I always go to a leap year. If I do a mod 2 or mod 4 I still get the same thing.
Use <> instead of = after mod? or put the 29 days when true and 28 days when false?
If you test 2023 mod 2 = 0 then this will be false and will push you to the code for leap year. The same for mod 4 = 0 (2023 will be false and then use the else section).
To determine whether a year is a leap year, follow these steps:
If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
most examples i saw create a date with the first day at next month and subtract a day.
via DateInterval or SubtractInterval
means you get the last day of month 28 or 29 in your case.
Why not simply try and create a date with the 29th Feb for the year. If it is invalid it should result in either an invalid date, an exception or a date which isn’t the 29th. Let the system / xojo do the work.