我在codeigniter中以strtotime格式存储日期。周从星期日开始。
$this->db->where($this->weight . '.create_date <=', 'curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY');
$this->db->where($this->weight . '.create_date >', 'curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY');
答案 0 :(得分:0)
上周参加:
WHERE date BETWEEN date_sub(now(),INTERVAL 1 WEEK) and now();
本周参加:
WHERE YEARWEEK(`date`, 1) = YEARWEEK(CURDATE(), 1)
上个月参加:
year(date(FROM_UNIXTIME(u.create))) = year(CURDATE() - INTERVAL 1 MONTH)
and month(date(FROM_UNIXTIME(u.create))) = month(CURDATE() - INTERVAL 1 MONTH)