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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏