How to query data expiration time in mysql php [closed]
How to query data expiration time in mysql php [closed]
In my Database I have products that i saved with the expiration timestamp in the format eg. 2018-22-08. Please how do I select all products that will expire in less than 4 days.
I have tried
SELECT * FROM table WHERE expiration_timestamp = DATE_ADD(CURDATE(), INTERVAL 4 DAY)
This question appears to be off-topic. The users who voted to close gave this specific reason:
Do you have
expiration_timestamp
values that are earlier than today (that also need to be filtered out)? If so, I might suggest BETWEEN
. By the way, expiration_timestamp
is a suboptimally named column. Don't you agree that expiration_date
makes better sense for you and future developers who may need to interact with your code/db? I get the sense that you haven't toiled very long before posting a question -- this seems very basic. (What does =
do?)– mickmackusa
Sep 15 '18 at 6:20
expiration_timestamp
BETWEEN
expiration_timestamp
expiration_date
=
1 Answer
1
You should use less than operator
SELECT * FROM table WHERE expiration_timestamp < DATE_ADD(CURDATE(), INTERVAL 4 DAY)
what did using that inside phpmyadmin show you or echoing / var_dump'ing the query?
– Funk Forty Niner
Sep 15 '18 at 1:49