[英]MySQL SELECT multiple tables and select date and compare to date today
I'm trying to select the date on my database and compare it to the date today. 我正在尝试选择数据库中的日期,并将其与今天的日期进行比较。 My current code has no error but it doesn't give me any result.
我当前的代码没有错误,但是没有任何结果。
My code: 我的代码:
$query = mysqli_query($mysqli, "select *, date_format(date, '%Y-%m-%d') from appointment
LEFT JOIN doctor
ON doctor.doctor_id = appointment.appointment_title
LEFT JOIN patient
ON patient.patient_id = appointment.patient_id
where appointment.appointment_title = $session_id AND
date(appointment.date) = CURDATE()
order by appointment.date ASC");
EDIT: 编辑:
Here's an example of appointment.date = 03/05/2018
and the data type is var 这是约会
03/05/2018
= 03/05/2018
的示例,数据类型为var
Use STR_TO_DATE()
function to convert date according to current date format 使用
STR_TO_DATE()
函数根据当前日期格式转换日期
$query = mysqli_query($mysqli, "SELECT *, STR_TO_DATE(date, '%d/%m/%Y') FROM appointment
LEFT JOIN doctor
ON doctor.doctor_id = appointment.appointment_title
LEFT JOIN patient
ON patient.patient_id = appointment.patient_id
WHERE appointment.appointment_title = $session_id AND
date(STR_TO_DATE(appointment.date, '%d/%m/%Y')) = CURDATE()
ORDER BY appointment.date ASC");
By using CURDATE() you have something like : 20180306 . 通过使用CURDATE(),您将得到: 20180306 。 Try this one :
试试这个:
$query = mysqli_query($mysqli, "select *, date_format(date, '%Y-%m-%d') from appointment
LEFT JOIN doctor
ON doctor.doctor_id = appointment.appointment_title
LEFT JOIN patient
ON patient.patient_id = appointment.patient_id
where appointment.appointment_title = $session_id AND
date(appointment.date) = DATE(CURDATE())
order by appointment.date ASC");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.