Despite Zend_Date‘s power and elegance to handle all kinds of different date and time formats, it (still) lacks the ability to cope with MySQL’s datetime formated strings out-of-the-box.
Thus, instead of being able to simply do something like
$date = new Zend_Date(); echo $date->toString(Zend_Date::MYSQL_DATETIME);
one has to manually define MySQL’s datetime syntax, as shown in the following:
$date = new Zend_Date(); echo $date->toString('YYYY-MM-dd HH:mm:ss');
I personally don’t quite see why this commonly used format has not yet been added to Zend_Date.
In the meantime, I have found it to be the most convenient to define the MySQL datetime format string as a constant. Although this is no big deal but still, I would rather like to see this simple piece of formating code inside Zend_Date.
I have come across a strange problem when trying to create new Zend_Date objects using custom formats, such as the MySQL datetime format shown above, e.g.:
$date = new Zend_Date($mysqlDatetimeString, MYSQL_DATETIME); //will create a wrong date...
Instead it seems best to create custom format dates/times using a two way approach:
$date = new Zend_Date(); //create new object, by default time() $date->set($mysqlDatetimeString, MYSQL_DATETIME); //will create correct date