开发者

Format date in MySQL

All,

I have a MYSQL table that has a column "DT_Created" defined with timestamp datatype. I would like to write a select query to retrieve the timestamp in the following fashion:

Sat, MM/DD/YYYY HH:MM:SS AM CST

Le开发者_如何学Pythonngthy Explanation:
Day, Month/Date/4 Digit Year Hours:Minutes:Seconds AM or PM TimeZone


Use the DATE_FORMAT command (see the Reference Manual).

SELECT DATE_FORMAT(DT_Created, '%a, %c/%d/%Y %T %p') AS formatted FROM ...

The time zone is a bit more difficult... I'm not even sure in which timezone it will format the time.


retrieve it by using a query as such:

$sql = "SELECT UNIX_TIMESTAMP(DT_Created) as timeToFormat FROM table";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

then you can format it with

$date = date("M/D/Y H:i:s",$row['timeToFormat']);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜