SQL Order by Oldest Unix Timestamps

How can I use SQL to order the results by oldest first? I am using unix timestamps.

Thanks.

+2


source to share


5 answers


The oldest UNIX timestamp is the smallest, which is why you want ORDER BY my_timestamp_column ASC

.



I have no idea why both answers so far pronounced column order DESC

.

+8


source


Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds that have passed since midnight prolepak. Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds

The ORDER BY clause can use ASC or DESC, if you disable it it will use ASC by default:

Most recent timestamps:



SELECT * FROM tableName ORDER BY columnName DESC

      

Less recent time stamps:

SELECT * FROM tableName ORDER BY columnName ASC

      

+3


source


What problem are you using ORDER BY 'unix-time-stamp-field' ASC;

?

EDIT: jemfinch

right it is ASC

.

+1


source


To get the oldest first data when used unix_timetamp

, run this query:

Select * FROM tablename order by FROM_UNIXTIME(ts) ASC

      

here: ts answer to the table column that has unix_timestamp

.

+1


source


Use ORDER BY

with a modifier DESC

that changes the results:

SELECT ... FROM ... ORDER BY timestampCol DESC;

      

Edit

Of course you should use ASC

(or none, the reason ASC

is the default) ...;)

0


source







All Articles