<p>Sounds like the work of a plugin! Unfortunately, there is no built in Entry API Event for setting anything when a new entry is created.</p>

<p>You could use <a href="http://buildwithcraft.com/docs/plugins/events-reference#entries-onBeforeSaveEntry" rel="nofollow">entries.onBeforeSaveEntry</a> to set $entry->expiryDate to three months from "now", but this wouldn't show until the user saved and returned to the entry. Use a function like this in your plugin's main class file.</p>

<pre><code>function init()
{
    craft()-&gt;on('entries.saveEntry', function(Event $event) {
        $entry = $event-&gt;params['entry'];
        $now = strtotime(date('Y-m-d H:i:s'));
        $entry-&gt;expiryDate = strtotime("+3 months", $now);
        $save = craft()-&gt;entries-&gt;saveEntry($entry);
    });
}
</code></pre>

<p>Hope this helps! </p>

CC BY-SA 3.0
2015-02-01T04:04:05.937Z
2015-02-01T04:04:05.937Z
Aaron Berkowitz
<p>If you haven't solved it yet with a custom solution, have a look at my <a href="https://github.com/carlcs/craft-autoexpire" rel="nofollow">Auto Expire</a> plugin. You would add a new expiration rule with the expiration date set to:</p>

<pre><code>{ 'now'|date_modify('+3 month 5am')|date('c') }
</code></pre>

<p>or</p>

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

<p>and make sure the option to allow user changes is checked.</p>

CC BY-SA 3.0
2015-05-13T15:58:59.837Z
2015-05-13T15:58:59.837Z
carlcs
<p>I need to automatically set the expire date of a new entry (only) from a specific section.</p>

<p>I know that it's possible to do this via the frontend twig templates, however I need the user to have the flexibility to change the date from the default that's set if they want to.</p>

<p>So when they create a new entry it'll have an expiration date of today + 3 months, but if they wanted they could change this date to next Wednesday or whatever they wanted.</p>

<p>Thanks for your help</p>

<entry>
Auto Expire on entries
# Auto Expire on entries

(Asked by: username_0 on 2015-01-19)

I need to automatically set the expire date of a new entry (only) from a specific section.

I know that it's possible to do this via the frontend twig templates, however I need the user to have the flexibility to change the date from the default that's set if they want to.

So when they create a new entry it'll have an expiration date of today + 3 months, but if they wanted they could change this date to next Wednesday or whatever they wanted.

Thanks for your help

**Tags:** entry

---

## 2 answers

### Answer by username_1 on 2015-02-01. Score: 2 | Accepted answer

Sounds like the work of a plugin! Unfortunately, there is no built in Entry API Event for setting anything when a new entry is created.
You could use entries.onBeforeSaveEntry to set $entry->expiryDate to three months from "now", but this wouldn't show until the user saved and returned to the entry. Use a function like this in your plugin's main class file.
function init()
{
    craft()->on('entries.saveEntry', function(Event $event) {
        $entry = $event->params['entry'];
        $now = strtotime(date('Y-m-d H:i:s'));
        $entry->expiryDate = strtotime("+3 months", $now);
        $save = craft()->entries->saveEntry($entry);
    });
}

Hope this helps!


---

### Answer by username_2 on 2015-05-13. Score: 3

If you haven't solved it yet with a custom solution, have a look at my Auto Expire plugin. You would add a new expiration rule with the expiration date set to:
{ 'now'|date_modify('+3 month 5am')|date('c') }

or
{ postDate|date_modify('+3 month 5am')|date('c') }

and make sure the option to allow user changes is checked.


---

