database - Mysql <= is giving the wrong output -
my table
starttime | endtime | id 10:30 11:30 1 11:30 12:30 2 14:30 16:30 3 15:30 16:30 4 if wanted select id's between 10:30 12:30 use below command
select id table str_to_date(starttime,'%h:%i')>='10:30' , str_to_date(endtime,'%h:%i')<='12:30'; this gives me id 1 ,but not giving me 2 , if change 12:30 12:40 gives me 1 & 2.but using less or equal should give me both id's right? why not working that?
the problem trying compare date object against string. precise, in following expression
str_to_date(starttime,'%h:%i') >= '10:30' str_to_date returns date, '10:30' varchar (which coincidentally looks time). if want continue down road, should cast both sides of comparison using str_to_date:
select id table str_to_date(starttime,'%h:%i') >= str_to_date('10:30','%h:%i') , str_to_date(endtime,'%h:%i') <= str_to_date('12:30','%h:%i'); but long term better approach make starttime , endtime columns either datetime or timestamp.
Comments
Post a Comment