Reputation: 157
I am trying to get the renewal_date column and get the month to check is that the exact month I want, and if so display the details of that record. My query is:
select domain_name, renewal_date
from hosting_details
where substr(renewal_date,-5,-3) = '09'
This doesn't give any result, but when I run below query I can retrieve results:
select domain_name, renewal_date
from hosting_details
where renewal_date = '2015-09-03'
I don't want to hard code the date, I want to retrieve any details which is in 09th month. How can I do it?
Upvotes: 1
Views: 41
Reputation: 16573
You should not perform a function on your (primary) WHERE statement. It will not use the index and perform a full table scan.
SELECT domain_name,renewal_date FROM hosting_details
WHERE renewal_date >= '01-09-2015' AND renewal_date < '01-10-2015'
Upvotes: 1
Reputation: 3488
You can try as below :
select domain_name,renewal_date from hosting_details where
date_format(renewal_date, '%m' ) = '09'
Upvotes: 0