开发者

is there a way to convert the time format in the mysql

开发者 https://www.devze.com 2023-03-23 05:41 出处:网络
the date style开发者_如何学编程 stored in the database is as this : 1310783109. eg: the date field is updatetime. when i using this:

the date style开发者_如何学编程 stored in the database is as this : 1310783109.

eg: the date field is updatetime. when i using this:

SELECT updatetime from node_software

then in my template file i using this {updatetime}. it outputs 1310783109. is there a way to format the date in the sql command then to make the output like this 07-28. namely, the month-the day. thank you.


You can do this using FROM_UNIXTIME:

SELECT FROM_UNIXTIME(`updatetime`, '%m-%d') AS `updatetime` 
  FROM `node_software`


FROM_UNIXTIME

Why are you not using MySQL's native date/time datatypes anyway?


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

SELECT DATE_FORMAT(NOW(), "%m-%d") as mydate

SELECT FROM_UNIXTIME(1310783109, "%m-%d") as mydate
0

精彩评论

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