<p>The version below could be more understandable in some cases.</p>

<p>First day of week <em>(assuming Monday is the first day)</em>:</p>

<pre><code>{{ now | date_modify('monday this week') | date('m-d-Y') }}
</code></pre>

<p>or alternatively:</p>

<pre><code>{{ now | date_modify('this week') | date('m-d-Y') }}
</code></pre>

<p>Last day of week <em>(assuming Sunday is the last day)</em>:</p>

<pre><code>{{ now | date_modify('sunday this week') | date('m-d-Y') }}
</code></pre>

<p>First day of month:</p>

<pre><code>{{ now | date_modify('first day of this month') | date('m-d-Y') }}
</code></pre>

<p>Last day of month:</p>

<pre><code>{{ now | date_modify('last day of this month') | date('m-d-Y') }}
</code></pre>

CC BY-SA 4.0
2019-05-15T15:44:28.793Z
2019-05-17T07:44:10.803Z
2019-05-17T07:44:10.803Z
Romain P.
<p>That code in Twig would be:</p>

<pre><code>{% set day = now|date('w') %}
{% set weekStart = now|date_modify("-#{day} days")|date('m-d-Y') %}
{% set weekEnd = now|date_modify("+#{6-day} days")|date('m-d-Y') %}
</code></pre>

CC BY-SA 3.0
2015-05-13T11:21:28.400Z
I noticed that there's a difference between `now` and `'now'`, Brandon. `now` not returning the date calculated to be in the right timezone?
carlcs
CC BY-SA 3.0
2015-06-24T16:12:02.310Z
@carlcs We fixed that in [Craft 2.4.2670](http://buildwithcraft.com/updates#build2670) :)
Brandon Kelly
CC BY-SA 3.0
2015-04-30T09:31:37.877Z
2015-04-30T09:31:37.877Z
Brandon Kelly
<p>If i provide the week#, how might i go about getting the first day (and month) and the last day (and month) of that particular week?</p>

<p>This week for instance would be April 26 and May 2</p>

<p>I know in PHP i can do the first and last day of the week like so:</p>

<pre><code>$day = date('w');
$week_start = date('m-d-Y', strtotime('-'.$day.' days'));
$week_end = date('m-d-Y', strtotime('+'.(6-$day).' days'));
</code></pre>

<p>But i'm not sure how to translate that to twig and of course also include the month.</p>

<templating><datetime>
First and Last day of Week + Month in Twig
# First and Last day of Week + Month in Twig

(Asked by: username_0 on 2015-04-30)

If i provide the week#, how might i go about getting the first day (and month) and the last day (and month) of that particular week?
This week for instance would be April 26 and May 2
I know in PHP i can do the first and last day of the week like so:
$day = date('w');
$week_start = date('m-d-Y', strtotime('-'.$day.' days'));
$week_end = date('m-d-Y', strtotime('+'.(6-$day).' days'));

But i'm not sure how to translate that to twig and of course also include the month.

**Tags:** templating, datetime

---

## 2 answers

### Answer by username_2 on 2015-04-30. Score: 9 | Accepted answer

That code in Twig would be:
{% set day = now|date('w') %}
{% set weekStart = now|date_modify("-#{day} days")|date('m-d-Y') %}
{% set weekEnd = now|date_modify("+#{6-day} days")|date('m-d-Y') %}

> **Comments:**
> **username_3**: I noticed that there's a difference between `now` and `'now'`, Brandon. `now` not returning the date calculated to be in the right timezone?  
> **username_2**: @carlcs We fixed that in [Craft 2.4.2670](http://buildwithcraft.com/updates#build2670) :)  

---

### Answer by username_1 on 2019-05-15. Score: 5

The version below could be more understandable in some cases.
First day of week (assuming Monday is the first day):
{{ now | date_modify('monday this week') | date('m-d-Y') }}

or alternatively:
{{ now | date_modify('this week') | date('m-d-Y') }}

Last day of week (assuming Sunday is the last day):
{{ now | date_modify('sunday this week') | date('m-d-Y') }}

First day of month:
{{ now | date_modify('first day of this month') | date('m-d-Y') }}

Last day of month:
{{ now | date_modify('last day of this month') | date('m-d-Y') }}


---

