Skip to content

SORT BY created_at, updated_at which are of type TEXT #26

Answered by benbjohnson
menzhessarov asked this question in Q&A
Discussion options

You must be logged in to vote

Hello! Good question. SQLite doesn't have a TIMESTAMP data type but fortunately RFC3339/ISO8601 is naturally lexicographically sortable:

"Date and time values are ordered from the largest to smallest unit of time: year, month (or week), day, hour, minute, second, and fraction of second. The lexicographical order of the representation thus corresponds to chronological order, except for date representations involving negative years or time offset. This allows dates to be naturally sorted by, for example, file systems."

ISO 8601, Wikipedia

If you're using Postgres or MySQL then you can use their TIMESTAMP data type directly. Although, if you're using SQLite, it does provide helper functio…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@menzhessarov
Comment options

@benbjohnson
Comment options

@menzhessarov
Comment options

@benbjohnson
Comment options

Answer selected by benbjohnson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants