I want to return all records that were added to the database within the last 30 days. I need to convert the date to mm/dd/yy because of display purposes.
create_date between DATE_FORMAT(curdate(),'%m/%d/%Y') AND (DATE_FORMAT(curdate() - interval 30 day,'%m/%d/%Y'))
My statement fails to limit the records to the last 30 days – it selects all the records.
Can anyone point me in the right direction? It feels like I am close.
Thanks and have a great week.
You need to apply
DATE_FORMATin theSELECTclause, not theWHEREclause:Also note that
CURDATE()returns only theDATEportion of the date, so if you storecreate_dateas aDATETIMEwith the time portion filled, this query will not select the today’s records.In this case, you’ll need to use
NOWinstead: