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   1011 Views

Avatar
priithansen

21 September 2012 at 8:52am Community Member, 25 Posts

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

21 September 2012 at 11:07am (Last edited: 21 September 2012 2:03pm), Community Member, 25 Posts

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();