user2177393
user2177393

Reputation: 99

Mysql timestamps and php date()

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

Upvotes: 8

Views: 25839

Answers (5)

xkeshav
xkeshav

Reputation: 54084

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'));

Upvotes: 17

RolandoMySQLDBA
RolandoMySQLDBA

Reputation: 44373

Try strptime()

strptime($date,"%H:%M:%S")

Upvotes: 0

Vaibhav Agarwal
Vaibhav Agarwal

Reputation: 238

Try this date('Y-m-d H:i:s',strtotime($date));

Upvotes: 0

Praveen kalal
Praveen kalal

Reputation: 2129

use this date('Y-m-d H:i:s',strtotime($date));

Upvotes: 21

Subedi Kishor
Subedi Kishor

Reputation: 5996

This might help you

date('H:i:s',strtotime($date));

Upvotes: 1

Related Questions