MySQL 按 Unix 时间戳 DESC 或 ASC 排序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5021276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORDER By Unix Timestamp DESC or ASC?
提问by PHPLOVER
I have news items that when created adds the time of creation date/time in unix timestamp format into the database. If i wanted to order by most recent first would i use ASC or DESC in my mysql query?
我有新闻项目,在创建时将 unix 时间戳格式的创建日期/时间添加到数据库中。如果我想最先订购,我会在我的 mysql 查询中使用 ASC 还是 DESC?
EDIT:
编辑:
Thanks everyone for replying. I understand now. I will make Sarfrazanswer the accepted solution as he was first to reply but thanks to everyone else to :) . Have to wait 11 minutes before i can accept it as a solution.
谢谢大家的回复。我现在知道了。我会让Sarfraz回答接受的解决方案,因为他是第一个回复的人,但感谢其他人:)。必须等待 11 分钟才能接受它作为解决方案。
回答by Marc B
DESC - timestamps are "higher = newer" number. So sorting by DESC(ending) will put the highest (newest) entries first.
DESC - 时间戳是“更高 = 更新”的数字。所以按 DESC(ending) 排序将把最高(最新)的条目放在最前面。
回答by dextervip
You should perform a SQL Query like below
您应该执行如下 SQL 查询
SELECT * FROM News ORDER BY date DESC
回答by Sarfraz
If i wanted to order by most recent first would i use ASC or DESC in my mysql query?
如果我想最先订购,我会在我的 mysql 查询中使用 ASC 还是 DESC?
You would order by DESC
for the most recent info or higher date.
您可以订购DESC
最新的信息或更高的日期。
回答by Chris Baker
Unix timestamp is number of seconds since the epoch (Dec. 1969). So, newer posts have a higher number, thus, sort DESC
.
Unix 时间戳是自纪元(1969 年 12 月)以来的秒数。因此,较新的帖子具有更高的数字,因此, sort DESC
。
回答by jondavidjohn
DESC
will put the largest first, which would be the most recent.
DESC
将把最大的放在最前面,这将是最近的。