Getting time and date from timestamp with php

2019-01-17 21:10发布

in my database I have a time stamp column...which reflects a format like this: 2012-04-02 02:57:54

However I would like to separate them up into $date and $time.

after some research through the php manual...I found that date() , date_format() and strtotime() are able to help me to separate them...(not sure if I am right)

but I not very sure of how to code it out...

In my php file...the timestamp extracted would be $row['DATETIMEAPP'].

Will

$date= strtotime('d-m-Y',$row['DATETIMEAPP']);
$time= strtotime('Gi.s',$row['DATETIMEAPP']);

or

$date= date('d-m-Y',$row['DATETIMEAPP']);

work?

Can i use date() to get the time as well??

Thanks in advance

7条回答
混吃等死
2楼-- · 2019-01-17 21:38
$mydatetime = "2012-04-02 02:57:54";
$datetimearray = explode(" ", $mydatetime);
$date = $datetimearray[0];
$time = $datetimearray[1];
$reformatted_date = date('d-m-Y',strtotime($date));
$reformatted_time = date('Gi.s',strtotime($time));
查看更多
登录 后发表回答