仅显示本月的所有结果 - Unix

Display All Results for this month Only - Unix

我有一些 UNIX 时间戳,我想显示当月的所有结果。当我显示结果时,视图上没有任何内容。

public static function getArrayMonthly($date_month){

    $currentDate = strtotime(date("Y-m-d", '1458086400'));

    $date_month = date('m', $currentDate);

    $sql = "SELECT * FROM events where date_start between $currentDate AND $date_month ORDER BY date_start ASC";
    $result = DB::select($sql);

    return($result);

} 

您目前正在将时间戳格式与月份数字进行比较,因此无法正常工作。

目前您的查询如下:

SELECT * FROM events where date_start between 1458014400 AND 03 ORDER BY date_start ASC

所以你的date_month应该是

$first_date_month = strtotime(date('Y-m-01 00:00:00', $currentDate));
$last_date_month = strtotime(date('Y-m-t 23:59:59', $currentDate));

此外,在您的 between 中,您必须从较旧的日期开始,所以它应该像

SELECT * FROM events where date_start between $first_date_month AND $last_date_month ORDER BY date_start ASC