Android Question SQL Order by Date

Mark.S

Member
Licensed User
Is there a way of ordering a date column when the saved format is dd/mm/yy
 

npsonic

Active Member
Licensed User
You mean something like this?
B4X:
sql1.ExecNonQuery("CREATE TABLE IF NOT EXISTS main(value1 NONE, value2 NONE, date NONE)")
sql1.ExecQuery("SELECT * FROM main ORDER BY date DESC")
 
Upvote 0

Mark.S

Member
Licensed User
Brilliant, thanks Mahares.
little by little I learn, didn't realize you could put kind of argument in a select
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Sqlite can do complex data manipulation like this but from a design perspective, if you are creating the data I would suggest that you convert the date to a number using the B4x DateTime functions and store that. You can the reconvert it for display and sorting and searching becomes simple and fast.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
My favorite way to store dates without time is this format; yyyymmdd or maybe: yyyy-mm-dd. You can sort asc, desc without any further manipulations. When you see the date, you can easily recognize it as a date. Some in the forum prefer ticks as in B4X Datetime functions. You tell me which one of the following looks like a date when you look at it:
the ticks: 1538798400000 or 20181006. For me it is a no-brainer, the second one. But people have different preferences and reasons.
 
Last edited:
Upvote 0
D

Deleted member 103

Guest

this is also my preferit, so you can also sort by hours, minutes and seconds if necessary.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…