2015-11-18 70 views
1

對於noob問題感到抱歉。但是,我該如何一次格式化日期和時間呢?如何在mysql中同時格式化日期和時間?

在此先感謝!

<? 
$sql = "SELECT *,date_format(course_date, '%d %b %Y') as course_date_format FROM course WHERE course_status = ? ORDER BY course_create_by"; 
$sql = "SELECT *,from_time_format(course_date, '%h:%i') as course_from_time_format FROM course WHERE course_status = ? ORDER BY course_create_by"; 
$sql = "SELECT *,to_time_format(course_date, '%h:%i') as course_to_time_format FROM course WHERE course_status = ? ORDER BY course_create_by"; 

$sth = $dbh->prepare($sql); 
$sth->execute(array($status)); 
while($result = $sth->fetch(PDO::FETCH_OBJ)){ 

$course_id = $result->course_id; 
$course_title = nl2br($result->{"course_title_".$lang}); 
$course_title1 = nl2br($result->{"course_title1_".$lang}); 
$course_date = $result->course_date_format; 

$course_from_time = $result->course_from_time; 
$course_to_time = $result->course_to_time; 
$course_time = $course_from_time_format."-".$course_to_time_format; 
?> 

回答

3

試試這個,

date_format(course_date, '%d %b %Y %H %i %s') 

H =>24小時格式 h =>12小時格式

Reference

+0

謝謝夥計!只是我正在尋找 – billybobjones

+1

考慮接受答案,如果它是有幫助的... –

+1

是的我會,對不起,說我必須等待9分鐘才能接受你的答案。但我不會擔心。再次感謝 – billybobjones