MYSQL PHP Sorting table rows with Full date names by date -
i have table there date field. values of items inserted there full date names.
how able sort selected result proper date?
example table
february 10, 2010 january 5, 2010 january 4, 2010 january 5, 2009 january 6, 2010 march 21, 2010
what want happen
january 5, 2009 january 4, 2010 january 5, 2010 january 6, 2010 february 10, 2010 march 21, 2010
is there mysql function this?
here query. date field named date
$sql = "select * `$table` order date";
unfortunately, sorts result alphabetically. how should modify/change query?
your future insights , feedback appreciated! :)
update
so problem field string/varchar
. possible change after data has been stored? , query above automatically sort correctly?
this because column in database setup string
/varchar
, versus datetime
field. there few ways approach this, easiest convert fields datetime fields instead.
an inefficient solution do:
$sql = "select * `$table` order str_to_date(`date`)";
this convert strings dates, , sort them, have every row in database cumbersome. bottom line: if you're working datetimes, use datetime
field.
Comments
Post a Comment