PHPLOVER
PHPLOVER

Reputation: 7257

ORDER By Unix Timestamp DESC or ASC?

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?

EDIT:

Thanks everyone for replying. I understand now. I will make Sarfraz answer 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.

Upvotes: 16

Views: 44465

Answers (5)

dextervip
dextervip

Reputation: 5059

You should perform a SQL Query like below

SELECT * FROM News ORDER BY date DESC

Upvotes: 6

jondavidjohn
jondavidjohn

Reputation: 62392

DESC will put the largest first, which would be the most recent.

Upvotes: 2

Marc B
Marc B

Reputation: 360642

DESC - timestamps are "higher = newer" number. So sorting by DESC(ending) will put the highest (newest) entries first.

Upvotes: 30

Chris Baker
Chris Baker

Reputation: 50592

Unix timestamp is number of seconds since the epoch (Dec. 1969). So, newer posts have a higher number, thus, sort DESC.

Upvotes: 2

Sarfraz
Sarfraz

Reputation: 382696

If i wanted to order by most recent first would i use ASC or DESC in my mysql query?

You would order by DESC for the most recent info or higher date.

Upvotes: 2

Related Questions