Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

SS3 ORM filter by Created date


Reply


2 Posts   1037 Views

Avatar
priithansen

Community Member, 25 Posts

21 September 2012 at 8:52am

Could somebody please help me figure out how to make a ORM sql query on a dataobject that returns the count of dataobjects created today. Cant figure it out in the new SS3 ORM.

Avatar
priithansen

Community Member, 25 Posts

21 September 2012 at 11:07am

Edited: 21/09/2012 2:03pm

Found a solution that seems to work:

DB::query("SELECT count(*) FROM Invoice WHERE Created BETWEEN '".date('Y-m-d')." 00:00:00' AND '".date('Y-m-d')." 23:59:59'")->value()


And that seems to be the right way

$count = Invoice::get()->filter(
      array(
   'Created:GreaterThan' => date('Y-m-d').' 00:00:00',
   'Created:LessThan' => date('Y-m-d').' 23:59:59'
      )
   )->count();