Date Range Approach

Hi all of you, i have a problem trying to get a date range in a CActiveDataProvider, is like a bithday reminder, i’ve an entry date

eg. 2010-04-06,

and I want that when

eg. 2013-03-31,

(7 days before event) comes, the date get into my dataprovider to send a notification, I try to use a addBetweenCondition but I must specify a year range and I dont know how to deal with… regards

Is this kind of what you’re looking for?




$today = date('Y-m-d');

$inSevenDays = strtotime(+7 day, $today);

$inSevenDays = date('Y-m-d', $inSevenDays);


$criteria = new CDbCriteria; 

$criteria->addBetweenCondition($column, $today, $inSevenDays, 'AND');


$dataProvider=new CActiveDataProvider($model, array('criteria'=>$criteria));



Thanx for the reply Selby, but it does not work for me, I explain you again,

I have a date stored in my BD eg. 1980-04-10,

I need a reminder when that date comes close eg. 2013-04-03, seven days before,

If I add a condition with addBetweenCondition like your code, the range goes from 2013-04-07 to 2013-04-14 and 1980-04-10 is not in that range by the year, I need to be a condition only for the day and month, clearer now?

You can keep day and month as you need, and try to use DateTime() class.




/* Fix first DateTime(); */

$dateOne = new DateTime();

$dateOne->setDate($year, $monthOne, $dayOne);


/* Fix second DateTime(); */

$dateTwo = new DateTime();

$dateTwo->setDate($year, $monthTwo, $dayTwo);


/* Note that $year must be the same as you need ... */


/* Get DateInterval object */

$interval = $dateTwo->diff(dateOne);


echo $interval->days; // ...



DateTime documentation

DateInterval documentation