<p>Twigs <a href="http://twig.sensiolabs.org/doc/filters/date_modify.html" rel="nofollow noreferrer">date_modify filter</a> accepts every string, which is supported by phps <a href="http://www.php.net/strtotime" rel="nofollow noreferrer">strtotime()</a>.</p>

<p>These strings are called <a href="http://www.php.net/manual/en/datetime.formats.relative.php" rel="nofollow noreferrer">Relative Formats</a>.</p>

<p>.</p>

<p><strong>Examples:</strong></p>

<p>In the <a href="https://craftcms.stackexchange.com/questions/168/how-do-i-show-advanced-filters-for-events">original post</a> you used:</p>

<pre><code>{% set day = date('m/d/Y') %}
{% set nextDay = day|date_modify('+1 day') %}
</code></pre>

<p>but with <a href="http://www.php.net/manual/en/datetime.formats.relative.php" rel="nofollow noreferrer">Relative Formats</a> you can also do something like this:</p>

<pre><code>{% set var = day|date_modify('now') %}
{% set var = day|date_modify('10 September 2000') %}
{% set var = day|date_modify('+1 week') %}
{% set var = day|date_modify('+1 week 2 days 4 hours 2 seconds') %}
{% set var = day|date_modify('next Thursday') %}
{% set var = day|date_modify('last Monday') %}
{% set var = day|date_modify('next month') %}
</code></pre>

<p>(These are equivalents of the <a href="http://www.php.net/strtotime#example-2413" rel="nofollow noreferrer">php-doc examples</a> )</p>

<p>.</p>

<p>So this weekend would be:</p>

<pre><code>{% set var = day|date_modify('next Friday') %}
</code></pre>

<p><em>Or Saturday, personally I start my weekends on Thursday, so it's hard to give a good example ;)</em></p>

<p>Next weekend:</p>

<pre><code>{% set var = day|date_modify('next Friday +7 days') %}
</code></pre>

<p>Next weekend in one year, half an hour ago:</p>

<pre><code>{% set var = day|date_modify('next Friday +1 year -30 minutes') %}
</code></pre>

CC BY-SA 3.0
2014-06-13T22:34:14.933Z
Beat me to it :)  And I had no idea you could use weekday names in date_modify! Very cool.
Brandon Kelly
CC BY-SA 3.0
2014-06-13T22:35:11.463Z
I also just found out after reading the docs, php still surprises from time to time.
Victor
CC BY-SA 3.0
2014-06-13T22:57:13.230Z
"Next weekend in one year, half an hour ago" — *finally*, I don't have to calculate this manually all the time!
Matt Stein
CC BY-SA 3.0
2014-06-14T19:23:54.017Z
How would you get the Dates in a Range though? You solution above works well for getting events on a certain day but a Weekend should show events from Friday through Sunday right?
Mark Busnelli Jr
CC BY-SA 3.0
2014-06-14T19:30:33.267Z
Does this help: http://craftcms.stackexchange.com/questions/47/how-can-i-use-operators-within-twig-hashes ?
Victor
CC BY-SA 3.0
2014-06-17T23:43:33.793Z
I'll take a look, looks like that post would get me what I'm after :) Thanks for all of the help!
Mark Busnelli Jr
CC BY-SA 3.0
2014-06-13T22:33:00.420Z
2014-06-13T22:33:00.420Z
2017-04-13T12:51:00.200Z
Victor
<p>Stemming from this <a href="https://craftcms.stackexchange.com/questions/168/how-do-i-show-advanced-filters-for-events">original post</a> I was able to show Events using a custom date field and successfully got "Today" and "Tomorrow" events to show up.</p>

<p>How would I go about doing some custom Math to show "This Weekend" or "Next Week" events? I'm sure I have to first write a conditional on determine what the current Day is, but not sure the best way to do this.</p>

CC BY-SA 3.0
2014-06-13T22:19:07.957Z
You might be able to unify these ideas into a beautiful macro or plugin. I only started on the macro quest today though, hence this timid comment instead of an authoritative answer.
Matt Stein
<entries><datetime>
How to show events for "This Weekend, Next Week"
# How to show events for "This Weekend, Next Week"

(Asked by: username_0 on 2014-06-13)

Stemming from this [original post](https://craftcms.stackexchange.com/questions/168/how-do-i-show-advanced-filters-for-events) I was able to show Events using a custom date field and successfully got "Today" and "Tomorrow" events to show up.

How would I go about doing some custom Math to show "This Weekend" or "Next Week" events? I'm sure I have to first write a conditional on determine what the current Day is, but not sure the best way to do this.

**Tags:** entries, datetime

> **Comments:**
> **username_1**: You might be able to unify these ideas into a beautiful macro or plugin. I only started on the macro quest today though, hence this timid comment instead of an authoritative answer.  

---

## 1 answers

### Answer by username_2 on 2014-06-13. Score: 23

Twigs date_modify filter accepts every string, which is supported by phps strtotime().
These strings are called Relative Formats.
.
Examples:
In the original post you used:
{% set day = date('m/d/Y') %}
{% set nextDay = day|date_modify('+1 day') %}

but with Relative Formats you can also do something like this:
{% set var = day|date_modify('now') %}
{% set var = day|date_modify('10 September 2000') %}
{% set var = day|date_modify('+1 week') %}
{% set var = day|date_modify('+1 week 2 days 4 hours 2 seconds') %}
{% set var = day|date_modify('next Thursday') %}
{% set var = day|date_modify('last Monday') %}
{% set var = day|date_modify('next month') %}

(These are equivalents of the php-doc examples )
.
So this weekend would be:
{% set var = day|date_modify('next Friday') %}

Or Saturday, personally I start my weekends on Thursday, so it's hard to give a good example ;)
Next weekend:
{% set var = day|date_modify('next Friday +7 days') %}

Next weekend in one year, half an hour ago:
{% set var = day|date_modify('next Friday +1 year -30 minutes') %}

> **Comments:**
> **username_3**: Beat me to it :)  And I had no idea you could use weekday names in date_modify! Very cool.  
> **username_2**: I also just found out after reading the docs, php still surprises from time to time.  
> **username_1**: "Next weekend in one year, half an hour ago" — *finally*, I don't have to calculate this manually all the time!  
> **username_0**: How would you get the Dates in a Range though? You solution above works well for getting events on a certain day but a Weekend should show events from Friday through Sunday right?  
> **username_2**: Does this help: http://craftcms.stackexchange.com/questions/47/how-can-i-use-operators-within-twig-hashes ?  
> **username_0**: I'll take a look, looks like that post would get me what I'm after :) Thanks for all of the help!  

---

