3

我需要你的日期时间覆盖帮助。在我的数据库中,我输入了这样的评论日期:

  Datetime: 2012-05-08 14:44:53

我怎样才能让它显示接近这个的东西

  May 15, 2012 2:44PM

感谢您的时间和耐心。

4

3 回答 3

2

DATE_FORMAT() 是您问题的答案。此链接上有多种日期格式

SELECT DATE_FORMAT(NOW(), '%M %d, %Y %h:%i %p') as FormattedDate;

在此处查看输出 [SQLFiddle]

%M  Month name (January..December)
%d  Day of the month, numeric (00..31)
%Y  Year, numeric, four digits
%h  Hour (01..12)
%i  Minutes, numeric (00..59)
%p  AM or PM
于 2012-05-27T12:09:40.440 回答
0

您需要使用strtotime()转换为 Unix 时间戳。然后,您可以使用它date()来显示您需要的确切格式。像这样的东西:

$unix = strtotime($datetime);
echo date(F j Y g:iA, $unix);
于 2012-05-27T11:52:57.603 回答
-1

您应该使用 MySQLDATE_FORMAT()功能。

参考:

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

示例查询:

SELECT DATE_FORMAT(`date`, '%a %d, %Y %l:%s%p') AS `myDate`;
于 2012-05-27T11:48:41.627 回答