I want to input a timestamp in below format to the database.
yyyy-mm-dd hh:mm:ss
How can I get in above format?
When I use
$date = new Zend_Date();
it returns month dd, yyyy hh:mm:ss PM
I also use a JavaScript calender to insert a selected date and it returns in dd-mm-yyyy format
Now, I want to convert these both format into yyyy-mm-dd hh:mm:ss so can be inserted in database. Because date format not matching the database field format the date is not inserted and only filled with *00-00-00 00:00:00*
Thanks for answer
I've always use
$date->__toString('YYYY-MM-dd HH-mm-ss');
method in the past but today didn't work. I was getting the default output of 'Nov 1, 2013 12:19:23 PM'So today I used
$date->get('YYYY-MM-dd HH-mm-ss');
as mentioned above. Seems to have solved my problem.You can find more information on this on output formats here: http://framework.zend.com/manual/1.12/en/zend.date.constants.html
This is how i did it:
this way you don't need to be concerned with whether or not its actually an instance of zend date, you can pass in a string or anything else that is a date.
this is i did it :
Zend_Date::now->toString('dd-MM-yyyy HH:mm:ss')
output from this format is "24-03-2012 13:02:01"
and you can modified your date format
Technically, @stefgosselin gave the correct answer for
Zend_Date
, butZend_Date
is completely overkill for just getting the current time in a common format.Zend_Date
is incredibly slow and cumbersome to use compared to PHP's native date related extensions. If you don't need translation or localisation in yourZend_Date
output (and you apparently dont), stay away from it.Use PHP's native
date
function for that, e.g.or DateTime procedural API
or DateTime Object API
Don't do the common mistake of using each and every component Zend Frameworks offers just because it offers it. There is absolutely no need to do that and in fact, if you can use a native PHP extension to achieve the same result with less or comparable effort, you are better off with the native solution.
Also, if you are going to save a date in your database, did you use any of the DateTime related columns in your database? Assuming you are using MySql, you could use a Timestamp column or an ISO8601 Date column.
a simple way to use Zend Date is to make specific function in its business objects that allows to parameter this function the date format. You can find a good example to this address http://www.pylejeune.fr/framework/utiliser-les-date-avec-zend_date/
Not sure if this will help you, but try using: