我如何从mysql获得上周,当前周和上个月的记录

时间:2015-03-09 06:17:37

标签: mysql codeigniter strtotime

我在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');

1 个答案:

答案 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)