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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -