MySQL选择多个表并选择日期并与今天的日期进行比较

问题描述 投票:0回答:2

我正在尝试在我的数据库中选择日期并将其与今天的日期进行比较。我当前的代码没有错误,但它没有给我任何结果。

我的代码:

$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

php mysql mysqli
2个回答
0
投票

使用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");

-1
投票

通过使用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");
© www.soinside.com 2019 - 2024. All rights reserved.