Jump to:

3431 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » SS3 ORM filter by Created date

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 913 Views
  • priithansen
    Avatar
    Community Member
    25 Posts

    SS3 ORM filter by Created date Link to this post

    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.

  • priithansen
    Avatar
    Community Member
    25 Posts

    Re: SS3 ORM filter by Created date Link to this post

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

    913 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.