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

1 Answer 1


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;
  • This did the trick. Thanks! I wasn't thinking at all in term of the timezone stuff. Very helpful.
    – Herb Himes
    Jul 31, 2015 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.