Last active
January 4, 2022 20:06
-
-
Save bootsified/314c4cefc3f6f45231c7544be0f40fd9 to your computer and use it in GitHub Desktop.
Get current week's range of dates (Craft/Twig)
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
{# CALCULATE THIS WEEK'S DATES #} | |
{% set todayNum = 'now' | date('w') %} | |
{% set startDate = 'now' | date_modify('-' ~ todayNum ~ ' day') %} | |
{% set endDate = startDate | date_modify('+6 day') %} | |
{% set endDateFormatted = '-' ~ endDate | date('j') %} | |
{% if startDate | date('M') != endDate | date('M') %} | |
{% set endDateFormatted = ' - ' ~ endDate | date('M j') %} | |
{% endif %} | |
<p>The Week of {{ startDate | date('M j') }}{{ endDateFormatted }}</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment