使用 PDO php 我试图获取我的数据库表中在当前一周内具有 start_date 的所有行。要计算本周的第一个和最后一个日期,我使用以下命令:
$week_start = date('d-m-Y',time()+( 1 - date('w'))*24*3600);
$week_end = date('d-m-Y',time()+( 7 - date('w'))*24*3600);
然后在我的 pdo 查询中,我有:
$query = "
SELECT
*
FROM
bookings as bb
INNER JOIN
reservation as br ON bb.booking_id=br.bookings_id
INNER JOIN
cars as bc ON br.car_id=bc.car_id
WHERE
payment_success=1 AND
is_block=false AND
is_deleted=0 AND
DATE_FORMAT(start_date, '%d-%m-%Y')
BETWEEN '".$week_start."' AND '".$week_end."'
";
try {
$stmt = DB::get()->prepare($query);
$stmt->execute();
$rows = $stmt->fetchAll();
}
catch(PDOException $ex) {
die("Failed to run query: " . $ex->getMessage());
}
foreach($rows as $row):
$row['booking_id'] etc...
endforeach;
问题是我没有在输出中显示任何行,尽管有多个预订的开始日期在本周内