Date calculation - Ignore Leap year

Hi, I need some help with a calculation in Mendix. I need to find numberofDays within a date range, but ignore if there is a Leap Day (29th Feb). Any suggestions on how to achieve this in Menidx?   Thank you,
4 answers


I am interested in the use case where the day is willingly removed. But well – there are multiple ways in doing so.

You will get the days between like this:

daysBetween(dateTime(2007, 2, 13, 1, 1, 1), dateTime(2007,1,1,1,1,1))

then you have to check whether or not the current year is a leap year. I just tested a sneaky way of doing that as follows:

parseDateTime('2020-02-29', 'yyyy-MM-dd')  // If your DateTime variable is in fact created as the 29th of february, then it is a leap year (like this year)

parseDateTime('2021-02-29', 'yyyy-MM-dd') // if it is not a leap year, Mendix will generate the 1st of March in this case! 


Edit: As Dave said, there is another way of checking for leap year. I found that model share.

As model share will be discontinued, here a description:

input of a datetime ‘testDate’, output boolean Expression

  • → Create Integer [ parseInteger(formatDateTime($testDate, 'yyyy')) ] → o [ if(($year mod 400 = 0) or (($year mod 4 = 0) and ($year mod 100 != 0))) then true else false  ]

Thanks Lukas and Dave.

I have used the same approach to determine the leap year. However, still having problem finding if the leap day falls between the range selected. Sorry guys, I am still finding my way around Mendix functions.



@Lukas – Sample use case in Insurance terms the days covered will always include the Leap day, though the premium will be collected only for 365 days :) Hope this explains your question.


This website ( )is quite helpfull for the mathematics behind it. A pity you can not upload to model share anymore because then you could have my microflow for calculating Long year.




Create a microflow with parameter integer and parameter name year. Then create a Decimal PY variable and put this inside it: $year + floor($year div 4) - floor($year div 100) + floor($year div 400).  Create another integer variable yearMinus1 and put this inside: $year - 1. Create another variable Decimal PYMinus1 and put inside this: $yearMinus1 + floor($yearMinus1 div 4) - floor($yearMinus1 div 100) + floor($yearMinus1 div 400). Then create a split and put this inside:

$PY mod 7 = 4 or
$PYMinus1 mod 7 = 3

If true then it is a Long year and false when it is not.



If you want to drop to Java, IsLeap is one line in a Java Action.

return java.time.Year.isLeap(this.Year);