I am using MySql database. and I am executing query like this:
select *
from Request
where
DATE_FORMAT(created_On,'%e/%m/%Y') between DATE_FORMAT(CURDATE() - 30, '%e/%m/%Y') and DATE_FORMAT(CURDATE(),'%e/%m/%Y')
it will return blank, means no records in result.
but if I write like this
select *
from Request
where
DATE_FORMAT(created_On,'%e/%m/%Y') between DATE_FORMAT(CURDATE() - 27, '%e/%m/%Y') and DATE_FORMAT(CURDATE(),'%e/%m/%Y')
It will fetch 100 hundred rows.
I want to ask that why i am subtract 30 days from current Date?
Assuming your date columns are proper
DATETIMEorDATEfields, you should not useDATE_FORMAT(). UseDATE_SUB()to subtract 30 days:If
created_OnisDATETIME, useDATE()to truncate off the time portion:If
created_OnisDATE, just use: