Skip to content
Home » Using DATE_FORMAT in Zend_DB query in Zend Framework

Using DATE_FORMAT in Zend_DB query in Zend Framework

It is very easy to use DATE_FORMAT in simple MySQL query like:
$sql = select DATE_FORMAT(STR_TO_DATE(DateTime`,’%Y%m%d’),’%Y%m%d’) from table;

But to use DATE_FORMAT using Zend_DB query format, query needs to be written in below format in zend framework.

 new Zend_Db_Expr (‘DATE_FORMAT( FROM_UNIXTIME(  `table_fieldname` ) ,  ‘%m/%d/%Y %h:%i:%s %p’ )’)

Example:
$sql = $db->select()
->from(array(‘tbl1’ => table1), array(‘firstname’
 new Zend_Db_Expr (‘DATE_FORMAT( FROM_UNIXTIME(  `table_fieldname` ) ,  ‘%m/%d/%Y %h:%i:%s %p’ )’)));

Leave a Reply

Your email address will not be published. Required fields are marked *

0 Shares
Tweet
Pin
Share
Share
Share