欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql取今日,明天,工作日,周末,本周,下周,下月数据

程序员文章站 2022-05-02 18:24:18
...

mysql取今天,明天,工作日,周末,本周,下周,下月数据 if ($date != '') {switch($date){//date_add 加 date_sub 减case '今天': $where .= " AND FROM_UNIXTIME(starttimefrom,'%Y-%m-%d') = curdate() "; break;case '明天': $where .= " AND FROM_UNIXT

mysql取今天,明天,工作日,周末,本周,下周,下月数据
if ($date != '') {
	switch($date){//date_add 加 date_sub 减
		case '今天':
            $where .= " AND FROM_UNIXTIME(starttimefrom,'%Y-%m-%d') = curdate() ";
            break;
		case '明天':
            $where .= " AND FROM_UNIXTIME(starttimefrom,'%Y-%m-%d') = date_add(curdate(), interval 1 day)";
            break;
		case '工作日':
            $where .= " AND dayofweek(FROM_UNIXTIME(starttimefrom)) not in (1,7) ";
            break;
        case '周末':
            $where .= " AND dayofweek(FROM_UNIXTIME(starttimefrom)) in (1,7) ";
            break;
        case '本周':
            $where .= " AND YEARWEEK(FROM_UNIXTIME(starttimefrom,'%Y-%m-%d')) = YEARWEEK(now())";
            break;
        case '下周':
            $where .= " AND ( FROM_UNIXTIME(starttimefrom,'%Y-%m-%d')>=SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-1) AND FROM_UNIXTIME(starttimefrom,'%Y-%m-%d')

?