php - MySQL Varchar to store dates, unsortable at years end? -


mysql database has years worth of records beginning in 2015, queries need use entries date having issue crossing 2015 2016. looking in database, date has been stored varchar. now, running query

select sum( salesprice ) total sales salesdate >=  '01-01-2016' , salesdate <=  '02-07-2016' 

the 'total' incorrect. correctly queries entries salesdate of 01-01-2016 through 01-07-2016 (the current day), continues add total using items last year.

what reasonable way convert column , reword query stop bug?

use str_to_date

select sum( salesprice ) total sales str_to_date(salesdate,'%m-%d-%y') >=  '2016-01-01' , str_to_date(salesdate,'%m-%d-%y') <=  '2016-02-07' 

note mysql uses date format y-m-d default, that's expects.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -