filtering elements between 2 dates I'm sure there must be an easy way to do this, but I can't work it out...

I'm trying to add date filters to the formerly submission export, but I can't work out how to filter out the submissions between 2 dates. I got it working with a bit of a hack:

$criteria = craft()-&gt;elements-&gt;getCriteria('Formerly_Submission');
$fromDate   = craft()-&gt;request-&gt;getPost('fromDate');
$fromDate = DateTime::createFromString($fromDate,   craft()-&gt;timezone) ;
$toDate   = craft()-&gt;request-&gt;getPost('toDate');
$toDate = DateTime::createFromString($toDate,   craft()-&gt;timezone) ;

//A bit of a hack, in my case these date fields are always the same anyway
$criteria-&gt;dateCreated = '&gt;= ' . $fromDate-&gt;format(DateTime::MYSQL_DATETIME);
$criteria-&gt;dateUpdated = '&lt;= ' . $toDate-&gt;format(DateTime::MYSQL_DATETIME);


I tried all sorts of ways to do it properly, things like

$criteria-&gt;dateCreated ='and, &gt; ' . $fromDate-&gt;format(DateTime::MYSQL_DATETIME) . ', &gt; ' . $toDate-&gt;format(DateTime::MYSQL_DATETIME)'


anyone know how to do it properly?
You call it a bit of a hack, but I think the way you're doing it is the proper way:

$criteria-&gt;dateCreated = '&gt;= ' . $fromDate-&gt;format(DateTime::MYSQL_DATETIME);
$criteria-&gt;dateUpdated = '&lt;= ' . $toDate-&gt;format(DateTime::MYSQL_DATETIME);


Your last example would work (with a syntax change) if you were you looking for a date range within a single field (either dateCreated or dateUpdated) like so, but not across two fields:

$criteria-&gt;dateUpdated = array('and', '&gt;='.$fromDate-&gt;format(DateTime::MYSQL_DATETIME), '&lt;='.$toDate-&gt;format(DateTime::MYSQL_DATETIME));