Saturday, September 19, 2009

Zend_Date

Using the Zend_Date class:

The following shows how you make a Zend_Date object from a MYSQL timestamp and how to do things with it.
 
$date = new Zend_Date($timestamp);

//Compare with now but first add a week.
$date->add('7', Zend_Date::DAY);
if($date->compare(new Zend_Date()) == -1) {
//$date has not accoured yet, since now is "smaller" than $date.
} else {
//$date has accoured, since now is "larger" than $date.
}

//Write it out in a way MYSQL timestamp understands
$sql_date_pattern = 'yyyy-MM-dd HH:mm:ss';
echo $date->get($sql_date_pattern);