Home > Database > Mysql Tutorial > mysql取今日,明天,工作日,周末,本周,下周,下月数据

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:15:05
Original
1571 people have browsed it

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')<=SUBDATE(CURDATE(),DATE_FORMAT(CURDATE(),'%w')-7) ) ";
            break;
        case '下月':
            $where .= " AND FROM_UNIXTIME(starttimefrom,'%Y-%m') =  date_format(DATE_add(curdate(), INTERVAL 1 MONTH),'%Y-%m') ";
            break;
		default:
	}	
}
Copy after login

?

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template