views:

770

answers:

2

I'm trying to build a query with propel Criteria to get all Foo's in a given month.

For example I want all Foo's in March. In regular SQL I would build a query like this:

SELECT * FROM FooPeer WHERE MONTH(startDate) = 3

Any Idea how I can implement the "MySQL Month-function within a Criteria Object" ?

$c = new Criteria();
$c -> add(FooEvent::START_DATE, 3, Criteria::EQUAL); //where do I have to put the Month function ?
return self::doSelect($c);
A: 

This question was partly answered there: How to use MySQL functions in Propel

Using Criteria::CUSTOM or writing custom SQL seem to be the only solutions.

altermativ
+1  A: 

Alright, a Custom Criteria did the job!

$month = 3; //march
$criteria->add(FooPeer::START_DATE, 'MONTH('.FooPeer::START_DATE.')='. $month, Criteria::CUSTOM);