Calculate the age for leap year in Clarion 8

If you want to calculate their 29th Feb Leap Year age, ie how many leap years have passed, knowing how to calculate the Leap year helps, then its a data range calculation after that.

  • Rule 1: If the year is evenly divisible by 4, it is a potential leap year. If not, it is definitely not a leap year.
  • Rule 2: If the year is also evenly divisible by 100 (a century year, e.g., 1900, 2100), it is not a leap year, overriding Rule 1.
  • Rule 3: If the century year is also evenly divisible by 400, it is a leap year, overriding Rule 2

Not tested: IF MONTH(DATE(2,29,year)) = 2 !is leap year

reminds me of the G&S operetta The Pirates of Penzance where Frederic is indentured to a band of pirates (which was meant to be “pilots” but his nursery maid Ruth was either hard of hearing or dipsy and got it wrong) until his 21st birthday. It turned out, however, that he was born on 29th February so when he reaches his 21st year and expects to be released from his duty, he in fact has another 63 years to go!

ditto for another variation

IF DAY(DATE(2,29,year)) = 29 !is leap year

It depends if you are confident the date funtions all work properly. I presume they do but seem to recall early versions of one of the spreadsheets (maybe Excel?) had1900 as a leap year (which it was not).

*** Just looked it up - it was Excel but it was done deliberately to be backwards compatible with Lotus 1-2-3 which had the bug.

It works since C8. In C5 I know it had trouble with invalid dates so wrote a DateFixed() function and CMag article.

These screen caps are from my Date Time Tool that lets you test Clarion Date functions without writing code. It shows 2027 is not a Leap Year (2/29/27 formats as 3/1) but 365 days later in 2028 it is because Date(2,29,2028) run thru Format() returns Date 2/29

2000 is Leap Year
image

2100 is not
image


You can also type any Clarion code to evaluate, like to check 2/29 in 1900:

image


The Leap Year logic that everyone that works with dates must know:

TheYear = YEAR(TheDate)
IF   TheYear % 4   =  0  |   ! Is Divisible by 4     Year % 4   = 0
AND (TheYear % 100 <> 0  |   !     and (Not by 100   Year % 100 > 0
  OR TheYear % 400 =  0 ) |  !  unless also by 400)  Year % 400 = 0
THEN 
   Message('Happy Leap Year '& TheYear )
END

! or choose ...
CHOOSE(TheYear%4=0 AND (TheYear%100<>0 OR TheYear%400=0),'Leap Year','Regular')

The current DATE() function cannot handle Negative Months, it will return -1. My Date Tool helps write the code to instead Subtract Years and Add Months.

2 Likes