Zend_Date is really a time saver class, I use it in almost every project I work, It handles time_zones, and date formatting pretty easy, leaving me more time to focus on other things.
The files that I need to use Zend_Date as a standalone class are:
Date.php and the Date folder from the Zend distribution package, and this is how I use it:
< ?php set_include_path('./lib' . PATH_SEPARATOR . get_include_path()); include_once 'Zend/Date.php'; $tugId = isset($_GET['tugId']) ? (int) $_GET['tugId'] : false; function formatDate($date) { /** * List of supported timezones * http://php.net/manual/en/timezones.php */ if ($date) { $fmtDate = new Zend_Date($date, Zend_Date::ISO_8601); $fmtDate->setTimezone('America/Los_Angeles'); return $fmtDate->toString(Zend_Date::DATETIME); } else { return ''; } } if (is_int($tugId)) { $sql = 'SELECT modified_date FROM tuggler WHERE tug_id = ' . $tugId; $result = $db->fetchAssoc($sql); $response = 'Last Record Update: '.formatDate($row['modified_date']) .''; } else { $response "nothing to return"; } echo $response;
The response from the above would be Jul 9, 2009 11:41:20 AM but I can easily change it using one of the predefined constants, or I can make my own format.



Matthias K. says:
Hello,
I am currently struggling with converting MySQL’s datetime format into a Zend_Date object. I’ve tried your code but unfortunately I cannot make Zend_Date to return the correct date or time for datetime values retrieved from the DB.
Did you choose a simple datetime field for modified_date in your example? Or any other varchar value?
Thanks in advance for any clarification.
Best regards
Matthias K. says:
UPDATE: it seems like I can’t use $fmtDate = new Zend_Date($date, Zend_Date::ISO_8601); directly but rather have to create a Zend_Date instance first and then set() the date and time:
$date = new Zend_Date();
$date->set($dateTimeStringFromMySQL, Zend_Date::ISO_8601);
Although it would be nice to get it working with only one function call, at least I got it to run now.
Best regards
Ivan Villareal says:
Good to know, perhaps you have a newer version of the framework? it always worked for me when passing the date when I do the object instantiation.