Mysql日期相关统计

DATE: 2016-08-12 / VIEWS: 806

//昨天
$firstDay = strtotime('-1 day 0:0:0');
$endDay = strtotime('-1 day 23:59:59');
//上周
$endDayOfWeek   = strtotime("last Sunday")+60*60*24;
$firstDayOfWeek = $endDayOfWeek - 60*60*24*7;
//本月
$firstDayOfMonth = strtotime(date('Y-m-1 0:0:0'));
//最近15天
$firstDayOfLast = strtotime('-15 day 0:0:0');

$Model = new Model();

//网站会员基本统计
$thisdaycount = $Model->query("SELECT count(id) as statnum FROM tp_users WHERE createtime BETWEEN {$firstDay} and {$endDay}");
$thisweekcount = $Model->query("SELECT count(id) as statnum FROM tp_users WHERE createtime BETWEEN {$firstDayOfWeek} and {$endDayOfWeek}");
$thismonthcount = $Model->query("SELECT count(id) as statnum FROM tp_users WHERE createtime >= {$firstDayOfMonth}");
$lastlogin = $Model->query("SELECT count(id) as statnum FROM tp_users WHERE lasttime >= {$firstDayOfLast}");
$allcount = $Model->query("SELECT count(id) as statnum FROM tp_users");