Created
March 18, 2021 17:22
-
-
Save peteeveleigh/fde73a37776ff60dec01799caafed21d to your computer and use it in GitHub Desktop.
Twig for figuring out number of days between 2 dates minus weekends/holidays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set start = '2020-01-01' %} | |
{% set end = '2021-03-17' %} | |
{% set holidays = ['2020-12-25', '2020-12-26', '2021-01-01'] %} | |
{% set difference = date(end).diff(date(start)) %} | |
{% set count = 0 %} | |
{% for i in 0..difference.days %} | |
{% set thisDay = start|date_modify(i ~ 'days') %} | |
{% set count = count + ((thisDay|date('D') not in ['Sun','Sat']) and (thisDay|date('Y-m-d') not in holidays)) %} | |
{% endfor %} | |
There are {{ count }} days between {{ start|date('jS F Y') }} and {{ end|date('jS F Y') }} not including weekends and holidays |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment