服务Q Q:75303307

网站优化

网站建设

工作时间:周一至周五:8:30-6:00 周六、日:9:00-5:00

技术点滴

您的位置:主页 > 新闻观点 > 技术点滴 > 详细内容>

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

2013-06-09 14:50 作者:admin [ ]
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:
	}	
}