0

我正在尝试在 php mysql 中获取当前日期、星期和月份的记录。日期列是日期类型。问题出在这里,我的周记录和月记录与下面的脚本相同。这是我的代码,看看。

public function getTodayComing(){
    $connection = db::factory('mysql');
    $sql = "select * from bookings,bookers where ";
    $qualifier = ' bookings.booker_id = bookers.id 
                  AND ((status ="'.AppGlobal::$bookingStatus['APPROVE'].'" 
                  OR status ="'.AppGlobal::$bookingStatus['RESCHEDULED'].'" 
                  OR status ="'.AppGlobal::$bookingStatus['RECONSULTED'].'") 
                  AND date=DATE( NOW() ))
                  ORDER BY date ASC';

    $sql. = $qualifier;     
    return  $valuearray = $connection->getArray ($sql );        
}
public function getWeekComing() {
    $connection = db::factory('mysql');
    $sql = "select * from bookings,bookers where ";
    $qualifier = ' bookings.booker_id = bookers.id 
                   AND ((status ="'.AppGlobal::$bookingStatus['APPROVE'].'" 
                   OR status ="'.AppGlobal::$bookingStatus['RESCHEDULED'].'" 
                   OR status ="'.AppGlobal::$bookingStatus['RECONSULTED'].'") 
                   AND date > DATE_SUB(NOW(), INTERVAL 1 WEEK)) ORDER BY date ASC';
    $sql. = $qualifier;
    return  $valuearray = $connection->getArray( $sql );
}
public function getMonthComing() {
    $connection = db::factory('mysql');
    $sql = "select * from bookings,bookers where ";
    $qualifier = ' bookings.booker_id = bookers.id 
                   AND ((status ="'.AppGlobal::$bookingStatus['APPROVE'].'" 
                   OR status ="'.AppGlobal::$bookingStatus['RESCHEDULED'].'" 
                   OR status ="'.AppGlobal::$bookingStatus['RECONSULTED'].'") 
                   AND date > DATE_SUB(NOW(), INTERVAL 1 MONTH)) ORDER BY date ASC';
    $sql. = $qualifier;
    return  $valuearray = $connection->getArray( $sql );
}
4

1 回答 1

0

啊,我才看到我觉得

date > DATE_SUB(...)

应该

date BETWEEN CUR_DATE() AND DATE_ADD(CUR_DATE(), INTERVAL 1 ...)
于 2013-08-08T09:01:49.160 回答