The mysql timestamp is in a standard format 2013-02-20 02:25:21, when I use date('H:i:s',$date) I get the same invalid output 18:33:33, how can I get the right output? hour:minute:seconds
The CURRENT_TIMESTAMP function in the MySQL database returns the current date and time (i.e. the time for the machine running that instance of MySQL). It is given as a value in the 'YYYY-MM-DD hh:mm:ss' format.
Specifies the format of the outputted date string. The following characters can be used: d - The day of the month (from 01 to 31)
The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.
use this date('Y-m-d H:i:s',strtotime($date));
Tip : try with MYSQL DATE_FORMAT
function
SELECT DATE_FORMAT('2013-02-20 02:25:21', '%H:%i:%s');
if you want to do it only with PHP then use strtotime
date('H:i:s',strtotime('2013-02-20 02:25:21'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With