<p>There's no build in functionality for this, but you could make a custom plugin that automatically sets the expiration date <code>expiryDate</code> when you first save an entry with a specific entry type.</p>

<p>Another option would be to simply filter your entries from your template:</p>

<pre><code>{% set entries = craft.entries.type('myEntryType').postDate('&gt;= ' ~ now|date_modify('-10 days')) %}
</code></pre>

<p>.</p>

<p><em>Edit:</em></p>

<p>Here's a description for the expression used as the value for the <a href="http://twig.sensiolabs.org/doc/filters/date_modify.html" rel="nofollow"><code>date_modify</code></a> parameter.</p>

<p>Have a look at the <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#parameter-value-syntax" rel="nofollow">syntax for parameter values</a> in the Craft docs. And also how the <a href="http://twig.sensiolabs.org/doc/filters/date_modify.html" rel="nofollow"><code>date_modify</code></a> filter works. <code>now|date_modify('-10 days')</code> returns a string which is then <a href="http://twig.sensiolabs.org/doc/templates.html#other-operators" rel="nofollow">concatenated</a> with the string <code>'&gt;= '</code> and then passed as a value to the <code>postDate()</code> parameter.</p>

CC BY-SA 3.0
2014-08-19T13:40:04.703Z
hi @carlcs. can you please give me more details on `.postDate('>= ' ~ now|date_modify('-10 days'))?`
lucassoares
CC BY-SA 3.0
2014-08-19T16:00:11.173Z
@lucassoares - carlcs postDate parameter is saying, make sure that he post date is greater than or equal to the timestamp of 10 days ago. It will guarantee that the entries returned are newer than 10 days old.
Wes Rice
CC BY-SA 3.0
2014-08-19T16:24:53.960Z
@Wes This is a nice description on what happens if you apply the parameter on a ElementCriteriaModel. I altered my answer to make it easier to understand the syntax used.
carlcs
CC BY-SA 3.0
2014-08-19T16:57:27.613Z
@WesRice that would make entries to become expired after 10 days from current date or it would just have their date modified to 10 days earlier from current date?
lucassoares
CC BY-SA 3.0
2014-08-19T17:02:41.140Z
@lucassoares both wrong. As I tried to explain in the answer, the only way to automatically set the expiration date is with a plugin. And the code example doesn't modify your entry in the DB. It is used in your template as a filter on an ElementCriteriaModel. If you use it like so, only entries newer then 10 days from the current moment `'now'` are returned. Compare it to the parameter `section()` where only entries from select sections are returned!
carlcs
CC BY-SA 3.0
2014-08-19T17:07:30.633Z
You'd have the same output from the Twig code, but the entries are still marked as "active" (status: green) in the Control Panel.
carlcs
CC BY-SA 3.0
2014-08-22T16:02:03.800Z
@carlcs Awesome, that would totally work for me. Should this code be in the single entry template or index template?
lucassoares
CC BY-SA 3.0
2014-08-22T16:16:26.350Z
Hehe, if you put it in the entry template it's already to late @lucassoares ;)
carlcs
CC BY-SA 3.0
2014-08-19T12:02:04.033Z
2014-08-19T17:04:49.627Z
2014-08-19T17:04:49.627Z
carlcs
<p>You could use my <a href="https://github.com/carlcs/craft-autoexpire" rel="nofollow">Auto Expire</a> plugin for this. Just add a new expiration rule with the expiration date set to:</p>

<pre><code>{ postDate|date_modify('+14 days 5am')|date('c') }
</code></pre>

CC BY-SA 3.0
2015-05-13T16:03:55.937Z
2015-05-13T16:03:55.937Z
carlcs
<p>Is there any way to set entries of an certain entry type to auto-expire after a certain number of days from the original post date? </p>

<entries><datetime><postdate>
How to set entries to auto-expire after certain # of days from post date?
# How to set entries to auto-expire after certain # of days from post date?

(Asked by: username_0 on 2014-08-19)

Is there any way to set entries of an certain entry type to auto-expire after a certain number of days from the original post date?

**Tags:** entries, datetime, postdate

---

## 2 answers

### Answer by username_1 on 2014-08-19. Score: 5

There's no build in functionality for this, but you could make a custom plugin that automatically sets the expiration date expiryDate when you first save an entry with a specific entry type.
Another option would be to simply filter your entries from your template:
{% set entries = craft.entries.type('myEntryType').postDate('>= ' ~ now|date_modify('-10 days')) %}

.
Edit:
Here's a description for the expression used as the value for the date_modify parameter.
Have a look at the syntax for parameter values in the Craft docs. And also how the date_modify filter works. now|date_modify('-10 days') returns a string which is then concatenated with the string '>= ' and then passed as a value to the postDate() parameter.

> **Comments:**
> **username_0**: hi @carlcs. can you please give me more details on `.postDate('>= ' ~ now|date_modify('-10 days'))?`  
> **username_2**: @lucassoares - carlcs postDate parameter is saying, make sure that he post date is greater than or equal to the timestamp of 10 days ago. It will guarantee that the entries returned are newer than 10 days old.  
> **username_1**: @Wes This is a nice description on what happens if you apply the parameter on a ElementCriteriaModel. I altered my answer to make it easier to understand the syntax used.  
> **username_0**: @WesRice that would make entries to become expired after 10 days from current date or it would just have their date modified to 10 days earlier from current date?  
> **username_1**: @lucassoares both wrong. As I tried to explain in the answer, the only way to automatically set the expiration date is with a plugin. And the code example doesn't modify your entry in the DB. It is used in your template as a filter on an ElementCriteriaModel. If you use it like so, only entries newer then 10 days from the current moment `'now'` are returned. Compare it to the parameter `section()` where only entries from select sections are returned!  
> **username_1**: You'd have the same output from the Twig code, but the entries are still marked as "active" (status: green) in the Control Panel.  
> **username_0**: @carlcs Awesome, that would totally work for me. Should this code be in the single entry template or index template?  
> **username_1**: Hehe, if you put it in the entry template it's already to late @lucassoares ;)  

---

### Answer by username_1 on 2015-05-13. Score: 2

You could use my Auto Expire plugin for this. Just add a new expiration rule with the expiration date set to:
{ postDate|date_modify('+14 days 5am')|date('c') }


---

