doutingyou2198 2016-03-16 22:27
浏览 49
已采纳

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

I have some UNIX time-stamps and I want to display all results for the current month. When I display the results there is nothing on the view.

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);

} 
  • 写回答

1条回答 默认 最新

  • doue2666 2016-03-16 22:52
    关注

    You are currently comparing a timestamp format with a month number so it could not work.

    Currently your query is like:

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

    So your date_month should be

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

    Also, in your between you have to start with the older date, so it should be like

    SELECT * FROM events where date_start between $first_date_month AND $last_date_month ORDER BY date_start ASC
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度