15

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.

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
PHPLOVER
  • 7,047
  • 18
  • 37
  • 54

5 Answers5

28

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

Marc B
  • 356,200
  • 43
  • 426
  • 500
6

You should perform a SQL Query like below

SELECT * FROM News ORDER BY date DESC
dextervip
  • 4,999
  • 16
  • 65
  • 93
2

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.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
2

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

Chris Baker
  • 49,926
  • 12
  • 96
  • 115
2

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

jondavidjohn
  • 61,812
  • 21
  • 118
  • 158