Search code examples
freemarker

Get the amount of specifc days in between two dates | in Freemarker


to explain the title or problem of my case. I want to get the amount of saturdays and sundays in between to dates. For example: Starting date is: 2022-02-01. Ending date is: 2022-02-07. So in between the dates are two weekend days or one saturday and on sunday.

Is there any way to calculate this or use a given fuction ?


Solution

  • There's nothing built in for that, so you had to expose some Java utility to the template to do that. Or better yet, the data-model should contain the final values to display. Generally if you have to do calculations in the template that's not a good sign.

    There's hope that 2.3.32 will be able to do more date/time calculations (because of java.time support). This of course even there will need some coding, but then it will be possible to do it purely in the template language. For now, you have to use Java for this.