Reputation: 127
SELECT * FROM users
WHERE birthday BETWEEN '08-06' AND '15-06'
This is my query to select data between two dates. I know this is duplicate question but their is slight problem to my situation.
The Dates which I m storing are manually inserted to db using dropdown list which is varchar datatype
Problem: The Results for this query only selects data using date(dd) values and not compares whole date string
This is the result i m getting which selects data from month 7 as well
bday
09-06-1985
08-06-1990
09-07-1991
Upvotes: 0
Views: 38
Reputation: 9289
Like other people write in comments, it's always best to use datetime data type for date. You can compare your varchar date like this
SELECT * FROM users
WHERE STR_TO_DATE(birthday, '%d-%m')
BETWEEN STR_TO_DATE('08-06', '%d-%m')
AND STR_TO_DATE('15-06', '%d-%m')
Upvotes: 1