views:

41

answers:

1

I'm having some trouble working out how to do comparisons on a datetime field, in the course of a CakePHP query.

I want for instance to be able to periodically delete all records from my database that relate to an event that occurred in the past. But I haven't gotten much further than:

$this->Item->deleteAll(
  'conditions'=>array('date'=> ... ),
  false
 );

Given that date is stored as a datetime, what's a good way of asking CakePHP to delete all items where the date is earlier than today?

+3  A: 
'conditions' => array('Item.date <' => date('Y-m-d'))
deceze
Thanks! For some reason I was making heavy weather of that. And if I wanted to select only items dated earlier than yesterday, I could use something like date('Y-m-d', strtotime("-1 day")) ...?
thesunneversets
@thes Sure, that'll work.
deceze