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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

SS3 ORM filter by Created date


Go to End


2 Posts   6876 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();