0

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);
Joe Doyle
  • 6,363
  • 3
  • 42
  • 45

2 Answers2

2

Alright, a Custom Criteria did the job!

$month = 3; //march
$criteria->add(FooPeer::START_DATE, 'MONTH('.FooPeer::START_DATE.')='. $month, Criteria::CUSTOM);
Fenton
  • 241,084
  • 71
  • 387
  • 401
0

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.

Community
  • 1
  • 1
altermativ
  • 690
  • 1
  • 6
  • 20