繁体   English   中英

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

[英]How do I format both the Date and Time at once in 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;
?>

尝试这个,

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

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

参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM