r/mysql • u/nextdoorneighbour_Hi • Sep 06 '24
question Grabbing exact date
Hi, I have been trying to filter my table to display product which where the expiry date is exactly 7 days from now but unfortunately it also grab the date within the 7 days....is there a way or is it possible to grab exactly the date that is 7 days from today (now())
1
Upvotes
1
u/r3pr0b8 Sep 06 '24
sure there is
what datatype is your date column? is it DATE, or DATETIME, or TIMESTAMP?
also, just so you know, NOW() is not today, it's this very second
if you want today, use CURRENT_DATE
1
u/Aggressive_Ad_5454 Sep 06 '24
Let's say you have an
expirycolumn in your table. And let's say it's aDATEdatatype.If you wanted to get the rows with an expiry of today you would do
If you wanted to get the rows with an expiry of seven days from now you would do
If you wanted to get all rows that expire on or before seven days from now you would do
1
u/hexydec Sep 06 '24
You should use
dateField=DATE_ADD(CURDATE(), INTERVAL 7 DAY).1
u/Qualabel Sep 06 '24
Your query looks fine to me