问题
i am storing date in strtotime format in codeigniter. and week start from sunday.
$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');
回答1:
For taking last week:
WHERE date BETWEEN date_sub(now(),INTERVAL 1 WEEK) and now();
For taking current week:
WHERE YEARWEEK(`date`, 1) = YEARWEEK(CURDATE(), 1)
For taking last month:
year(date(FROM_UNIXTIME(u.create))) = year(CURDATE() - INTERVAL 1 MONTH)
and month(date(FROM_UNIXTIME(u.create))) = month(CURDATE() - INTERVAL 1 MONTH)
来源:https://stackoverflow.com/questions/28936174/how-can-i-get-last-week-current-week-and-last-month-record-from-mysql