本文介绍了我如何从MySQL获取上周,当前周和上个月的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将strtotime格式的日期存储在codeigniter中.和星期从星期日开始.

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

推荐答案

上周服用:

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)

这篇关于我如何从MySQL获取上周,当前周和上个月的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 02:59