Mysql select - 获取时间戳的日期
在mysql表中,存储了时间戳值(如1265138145)。 我想要的是显示属于这些时间戳的日期(例如27/2/2011、10/3/2011、15/3/2011、16/03/2011等)。这可能吗? (但只显示一次日期,例如如果有 1265138145 和 1265138140 则只显示一次日期 - 即 16/3)
At the mysql table, there are stored values of timestamps (like 1265138145).
What i want is to display the dates (eg 27/2/2011,10/3/2011,15/3/2011, 16/03/2011 etc) which belong to these timestamps. Is this possible?
(but only display one time the date, eg if there is 1265138145 and 1265138140 then display only one time the date - which is 16/3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有多种方法可以做到这一点, FROM_UNIXTIME 命令可能是最简单的。
例如:
SELECT FROM_UNIXTIME(, '%d/%m/%Y');
我不确定您所说的“仅显示一次日期”是什么意思,但是在必要的列上使用
DISTINCT
应该会有所帮助。即:
SELECT DISTINCT(FROM_UNIXTIME(, '%d/%m/%Y'));
可能就是您所需要的。There are a variety of ways of doing this, the FROM_UNIXTIME command probably being the easiest.
For example:
SELECT FROM_UNIXTIME(<timestamp field>, '%d/%m/%Y');
I'm not sure what you mean about "only display one time the date", but using
DISTINCT
on the necessary column should help.i.e.:
SELECT DISTINCT(FROM_UNIXTIME(<timestamp field>, '%d/%m/%Y'));
may be all you require.在 MySQL 中,使用 ADDDATE 和unixtimestamp秒到纪元的间隔,例如
在查询中使用 DISTINCT,例如
上面的两个查询都将列返回为日期时间值,您可以在 PHP 中应用默认格式。
Note about using FROM_UNIXTIME - you get your local UTC offset added to the time, which is unlikely to be what you want, unless the data was populated using UNIX_TIMESTAMP in the first place.
From within MySQL, use ADDDATE and interval of unixtimestamp seconds to the epoch, e.g.
Use DISTINCT in your query, e.g.
Both queries above return the column as a datetime value, which you can apply default formatting to in PHP.
Note about using FROM_UNIXTIME - you get your local UTC offset added to the time, which is unlikely to be what you want, unless the data was populated using UNIX_TIMESTAMP in the first place.
http://us.php.net/manual/en/function.date.php
http://us.php.net/manual/en/function.date.php
获取您的数据并仅使用
date()
函数。Fetch your data and use just
date()
function.使用 FROM_UNIXTIME(unix_timestamp), FROM_UNIXTIME(unix_timestamp,format) http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_from-unixtime
mySQL 语句中的
use
FROM_UNIXTIME(unix_timestamp), FROM_UNIXTIME(unix_timestamp,format)
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_from-unixtimein mySQL statement