如何在mysql中一次格式化日期和时间?

时间:2015-11-18 04:32:18

标签: php 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;
?>

1 个答案:

答案 0 :(得分:3)

试试这个,

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

H =&gt; 24小时格式 h =&gt; 12小时格式

Reference