Reputation: 12696
I've got a system built in CakePHP and one of the selection fields for the data is a year. Is there a simple way to put something into the condition array to match date on the selected year?
Upvotes: 3
Views: 3808
Reputation: 91
In your find conditions use:
$conditions = array('YEAR(Model.date)' => '2009');
Upvotes: 9
Reputation: 522091
I'm just going to go out on a limb and guess that your question is
I have a date field in the database that stores dates like '2009-08-03'. How can I select all dates of 2009 using Cake?
In which case my answer would be that the simplest way is probably this:
$conditions = array(
'Model.date >=' => "$year-01-01",
'Model.date <=' => "$year-12-31"
);
Mind Reader http://uvshock.co.uk/badges/badge.php?label=Mind%20reader&medal=bronze
Upvotes: 4
Reputation: 12064
You mean date("Y")
? See http://php.net/manual/en/function.date.php
Upvotes: 1