sql - MYSQL Fetch Date and Time Stored as String and ORDER BY -


i have specific reason storing date , time in database table string in below format

datefmt = "dd-mm-yyyy";
timefmt = "hh:mm a";

now while fetching want sort converting string date , time , sort display in tableview, row newer ones come on top.

this wil work if store date , time,

order `date` desc, `time` desc 

how convert string , use order by

use str_to_date():

order str_to_date(date, '%d-%m-%y') 

i should add: can think of no reason storing date in format in database. should using built-in date/time types. exist reason.

if have store date string (which have occasionally), should use yyyy-mm-dd format. iso standard, converts readily date, , sorts correctly.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -