Skip to content

Instantly share code, notes, and snippets.

@bootsified
Last active January 4, 2022 20:06
Show Gist options
  • Save bootsified/314c4cefc3f6f45231c7544be0f40fd9 to your computer and use it in GitHub Desktop.
Save bootsified/314c4cefc3f6f45231c7544be0f40fd9 to your computer and use it in GitHub Desktop.
Get current week's range of dates (Craft/Twig)
{# 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