Answer the question
In order to leave comments, you need to log in
How to select current date + 5 days from database in SQL?
Hello gentlemen!
Tell me please.
It is necessary to select only those users who have an appointment for 5 days in advance.
Here is the request itself:
SELECT patients.fio, patients.number_phone,
appointment.date_of_appointment,
appointment.time_of_appointment
FROM appointment
INNER JOIN patients
WHERE DATE_ADD(CURDATE(), INTERVAL 5 day) >= appointment.date_of_appointment
AND patients.user_id = appointment.user_id;
Answer the question
In order to leave comments, you need to log in
Well, you are still doing the right thing)) But not completely.
CURDATE+5 is greater than date_of_appointment
This means date_of_appointment is less than CURDATE+ 5.
But how to cut off the past days? We also need date_of_appointment > CURDATE
Well, the condition, if it is more carefully expressed in words, should sound like
"located between the current date and the date 5 days more",
that is, at least two comparisons or between
p / s / it is usually more convenient to operate with something like datediff - yes the difference in days and there you can more clearly see what you need " from zero to 5 days"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question