Php MySQL选择多个表并选择date并与date today进行比较
我正在尝试选择数据库中的日期,并将其与今天的日期进行比较。我当前的代码没有错误,但没有给出任何结果 我的代码:Php MySQL选择多个表并选择date并与date today进行比较,php,mysql,mysqli,Php,Mysql,Mysqli,我正在尝试选择数据库中的日期,并将其与今天的日期进行比较。我当前的代码没有错误,但没有给出任何结果 我的代码: $query = mysqli_query($mysqli, "select *, date_format(date, '%Y-%m-%d') from appointment LEFT JOIN doctor ON doctor.doctor_id = ap
$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");
编辑:
下面是appointment.date=03/05/2018
的示例,数据类型为var使用stru 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");
通过使用CURDATE(),您可以得到如下内容:20180306。
试试这个:
$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");
我没有看到你的查询中有任何明显的错误。您可能希望向我们展示一些示例数据以及您期望的输出。您能否提供一个
约会的示例。date
我用约会的示例编辑了我的帖子。dateah好吧,这就是问题所在,您需要将日期存储为嗯,日期(YYYY-MM-DD)这是唯一的问题吗?我将日期存储在错误的数据类型中?可能非结果来自联接的语法。我不确定,试试看