Dates Expiring By Custom Field date_modify Can I somehow set the expiration date of an entry based on a custom-field. I ask this because I don't want the site-owner to have to manually set the expiration date (for multiple reasons)but they are setting a 'start' date in a custom field. I am currently outputting entries and limiting them by doing this:

{% for event in entries %}
                    {% set count = 0 %}
                    {% if count &lt; 5 and event.dateTime|date_modify('tomorrow 5am')|date('U') &gt; now|date('U') %}


It would be really fantastic though if i was able to use that same date_modify to expire the entry and remove the entries from the loop all-together due to being expired.
You could write a fairly simple plugin to automatically set the expiration based off of another field value or calculation.

In your plugin's main file:

public function init() {

    parent::init();

    craft()-&gt;on('entries.saveEntry', function(Event $event) {

        $entry = $event-&gt;params['entry'];

        if ($entry-&gt;section == 'Events') {

            if (empty($entry-&gt;expiryDate)) {
                $date = new DateTime($entry-&gt;dateTime);
                $modifiedDate = date_modify($date, 'tomorrow 5am');
                $entry-&gt;expiryDate = $modifiedDate;
                craft()-&gt;entries-&gt;saveEntry($entry);
            }

        }

    });

}


Updated Code fixed syntax errors and added a check to see if expiration date is already set, otherwise created an endless loop (and may overwrite a manual setting).