Reputation: 200
I've tried to google the answer, but found nothing, also neither MySQL BETWEEN page nor MySQL Pattern matching page have any information about it.
So, I'm curious, is it correct to use SQL patterns in BETWEEN operator, like SELECT * FROM table WHERE date BETWEEN '2019-01-01%' AND '2019-02-01%'
in case of date
pattern is Y-m-d H:i
.
It is not recommended to use SQL patterns in =, > and < cases, but nothing about BETWEEN
Upvotes: 0
Views: 182
Reputation: 1271003
First, there is no like
support with between
. It just doesn't make sense.
Second, you should not be using string functions on dates. MySQL has lots of really useful string fucntions.
And finally, you can just use regular comparisons:
where date >= '2019-01-01' and date < '2019-02-02'
Ironically, this will work both when the date column is stored (properly) as a date
. And also what it is stored as a datetime
. And as a string (given the format you specify).
Upvotes: 1