<p>I'm not sure if there's some other Craft helpers / static variables that you could use, but this technique works. Create a DateTime object without the param set to get the current time, modify it and format it for use in the query like so:</p>

<pre><code>$date = new DateTime();
$date-&gt;modify('-7 days');

// Format datetime for use in query
$timezone = new \DateTimeZone(DateTime::UTC);
$date = $date-&gt;format(DateTime::MYSQL_DATETIME, $timezone);

$criteria-&gt;dateUpdated = '&gt; '.$date;
</code></pre>

CC BY-SA 3.0
2015-07-31T21:25:21.040Z
This did the trick. Thanks! I wasn't thinking at all in term of the timezone stuff. Very helpful.
Herb Himes
CC BY-SA 3.0
2015-07-31T21:05:46.860Z
2015-07-31T21:05:46.860Z
carlcs
<p>My plugin function is ignoring the dateUpdated criteria. Any clue as to why? I'm guessing it's syntax, but I cannot find any examples online as to how to format correctly. I can make this work in a template just fine. I'm new to plugins and PHP. Thanks!</p>

<pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
    $criteria-&gt;section = 'guide';
    $criteria-&gt;order = 'postDate desc';
    $criteria-&gt;dateUpdated  &gt; '("now"|date_modify("-7 days"))';
    $entries = $criteria-&gt;find();

    if ($entries) {
        //Do that thing with my code
    }
</code></pre>

<plugin-development><entries><elementcriteriamodel>
Plugins - Element Criteria Model. Can I return only entries with a updated date in the last 7 days?
# Plugins - Element Criteria Model. Can I return only entries with a updated date in the last 7 days?

(Asked by: username_0 on 2015-07-31)

My plugin function is ignoring the dateUpdated criteria. Any clue as to why? I'm guessing it's syntax, but I cannot find any examples online as to how to format correctly. I can make this work in a template just fine. I'm new to plugins and PHP. Thanks!
$criteria = craft()->elements->getCriteria(ElementType::Entry);
    $criteria->section = 'guide';
    $criteria->order = 'postDate desc';
    $criteria->dateUpdated  > '("now"|date_modify("-7 days"))';
    $entries = $criteria->find();

    if ($entries) {
        //Do that thing with my code
    }

**Tags:** plugin-development, entries, elementcriteriamodel

---

## 1 answers

### Answer by username_1 on 2015-07-31. Score: 6 | Accepted answer

I'm not sure if there's some other Craft helpers / static variables that you could use, but this technique works. Create a DateTime object without the param set to get the current time, modify it and format it for use in the query like so:
$date = new DateTime();
$date->modify('-7 days');

// Format datetime for use in query
$timezone = new \DateTimeZone(DateTime::UTC);
$date = $date->format(DateTime::MYSQL_DATETIME, $timezone);

$criteria->dateUpdated = '> '.$date;

> **Comments:**
> **username_0**: This did the trick. Thanks! I wasn't thinking at all in term of the timezone stuff. Very helpful.  

---

