Order query by string?

I have “timestamps” stored in db as strings. 01:00, 02:50, 03:41, 06:00, 23:05, etc. i want to select them in this order:


Can i do this directly in the query or does it have to be done after the data has been fetched?

why are they stored as strings?

becasue they are only used for showing the time of the event. would it make any different making them timestamps?

Well they should be stored for what they are. Then you format them however you want. A string doesn’t allow that

Well, it is correct that timestamps can be stored as epoc time. It is customary to do that. However, If you are storing it as a string, Your query can get the result ordered in sequence. All you have to do is add an “ORDER BY” clause to your query. Like:
SELECT Name, Address, Phone FROM contacts WHERE phone is like “312%” ORDER BY timestamp.
It is useful to people to make suggestions on how they might improve their coding. It’s would also seem to be useful to answer the question. Sometimes a database schema is out of the control of the person creating a script to query the data.

Sponsor our Newsletter | Privacy Policy | Terms of Service