Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-31T21:25:21.040Z
Answers.Text: This did the trick. Thanks! I wasn't thinking at all in term of the timezone stuff. Very helpful.
Answers.UserDisplayName: Herb Himes
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-31T21:05:46.860Z
Answers.LastActivityDate: 2015-07-31T21:05:46.860Z
Answers.UserDisplayName: carlcs
Body: <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>
  
Tags: <plugin-development><entries><elementcriteriamodel>
Title: Plugins - Element Criteria Model. Can I return only entries with a updated date in the last 7 days?
ThreadText: # 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.  
  
  ---
  
  