thinkphp 怎么查本周 本月时间范围内的数据

如题所述

    求本周的开始和结束时间

    $w = date('w',time()) - 1; 

    $start_time = time() - $w * 60 * 60 * 24;         //星期一的时间戳

    $end_time = time() + (6 - $w) * 60 * 60 * 24; //星期天的时间戳
    M('tablename')->where("create_time >=  {$start_time} and create_time <= $end_time")->select();

    月份的也很简单了,求出本月开始和结束的时间,然后在根据时间查询就可以了

温馨提示:答案为网友推荐,仅供参考