Tony
Tony

Reputation: 1129

MySQL convert between two date format

The user will enter the date in this format : 17-Feb-2017

and the date stored in mysql db is in this format : 2015-02-17 00:00:00

what I tried to do is

SELECT * FROM insurance where DATE_FORMAT(in_date,'%d-%b-%Y') > '17-Feb-2017';

DATE_FORMAT(in_date,'%d-%b-%Y') return the date in this format : 17-Feb-2017

but that not working !!

any suggestions ?

Upvotes: 0

Views: 348

Answers (1)

Jens
Jens

Reputation: 69450

Convert the input to a date type and the column value too:

SELECT * FROM insurance where date(in_date) > STR_TO_DATE('17-Feb-2017','%d-%b-%Y')

For more explanation about STR_TO_DATE and DATE function see the mysql documentation. Do not convert both values to string, because you can not compare it after the convertion

Upvotes: 1

Related Questions