c# - MySQL - Using 'WHERE Column LIKE' in the right DateTime format -
i'm trying implement search function mysql. in application have page user sees table database. pretty sees see when running select * table
my table has integers, strings , datetimes. want user can type in searchbox , list of row has substring of text user searching for.
first, using concat 1 large string of every column in table row. here example:
select name, fullname mytable lower(concat(name, ' ', fullname, ' ') '%m%'); the problem: lets want every record 24.04. run following code:
select name, fullname, date mytable date '%24.04%'; the problem column date isnt in same format. stored 2008-24-04 12:26:43.
i have tried using date_format. not seem work
select name, fullname, date mytable lower(concat(name, ' ', fullname, ' ', date_format(date, "%d.%l.%y"), ' ') '%22.04%'); note user should able search in table. not dates. should still using like '%xyz%'.
how solve this? changing on database-model not allowed.
you can use day , month functions:
select name, fullname, date mytable month(date) = 4 , day(date) = 24; the last select rewritten this:
select name, fullname, date mytable lower(concat(name, ' ', fullname, ' ')) '%22.04%' , month(date) = 4 , day(date) = 22; but don't see why check names against date
edit
in question said tried format date. in format string there error. used date_format(date, "%d.%l.%y") convert "day.hour.year". should give right result: date_format("2017-06-15", "%d.%m.%y")
Comments
Post a Comment