复杂的时间判断,搞得头疼,记住我的这些代码吧
<?php
$now = time();
//今天
$beginTime = date('Y-m-d 00:00:00', $now);
$endTime = date('Y-m-d 23:59:59', $now);
//昨天
$time_zuotian = strtotime('-1 day', $now);
$beginTime_zuotian = date('Y-m-d 00:00:00', $time_zuotian);
$endTime_zuotian = date('Y-m-d 23:59:59', $time_zuotian);
//本周
$time_benzhou = '1' == date('w') ? strtotime('Monday', $now) : strtotime('last Monday', $now);
$beginTime_benzhou = date('Y-m-d 00:00:00', $time_benzhou);
$endTime_benzhou = date('Y-m-d 23:59:59', strtotime('Sunday', $now));
//本月
$beginTime_benyue = date('Y-m-d 00:00:00', mktime(0, 0, 0, date('m', $now), '1', date('Y', $now)));
$endTime_benyue = date('Y-m-d 23:39:59', mktime(0, 0, 0, date('m', $now), date('t', $now), date('Y', $now)));
//半年
$time_bannian = strtotime('-5 month', $now);
$beginTime_bannian = date('Y-m-d 00:00:00', mktime(0, 0,0, date('m', $time_bannian), 1, date('Y', $time_bannian)));
$endTime_bannian = date('Y-m-d 23:39:59', mktime(0, 0, 0, date('m', $now), date('t', $now), date('Y', $now)));
//一年
$beginTime_yinian = date('Y-m-d 00:00:00', mktime(0, 0,0, 1, 1, date('Y', $now)));
$endTime_yinian = date('Y-m-d 23:39:59', mktime(0, 0, 0, 12, 31, date('Y', $now)));
//三年
$time_sannian = strtotime('-2 year', $now);
$beginTime_sannian = date('Y-m-d 00:00:00', mktime(0, 0, 0, 1, 1, date('Y', $time_sannian)));
$endTime_sannian = date('Y-m-d 23:39:59', mktime(0, 0, 0, 12, 31, date('Y')));
?>
<?php
//作者主页 https://www.bz80.vip
//今日询盘
$sql01 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime' ) AND `jindushijian` <= unix_timestamp( '$endTime' ) and jindu=1";
$rs01 = $pdo->query($sql01)->fetchColumn();
$today_num01 = $rs01;
//今日报价
$sql02 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime' ) AND `jindushijian` <= unix_timestamp( '$endTime' ) and jindu=2";
$rs02 = $pdo->query($sql02)->fetchColumn();
$today_num02 = $rs02;
//今日样品
$sql03 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime' ) AND `jindushijian` <= unix_timestamp( '$endTime' ) and jindu=3";
$rs03 = $pdo->query($sql03)->fetchColumn();
$today_num03 = $rs03;
//今日定金
$sql04 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime' ) AND `jindushijian` <= unix_timestamp( '$endTime' ) and jindu=5";
$rs04 = $pdo->query($sql04)->fetchColumn();
$today_num04 = $rs04;
//今日生产
$sql05 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime' ) AND `jindushijian` <= unix_timestamp( '$endTime' ) and jindu=6";
$rs05 = $pdo->query($sql05)->fetchColumn();
$today_num05 = $rs05;
?>
<?php
//本周询盘
$sql01 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benzhou' ) AND `jindushijian` <= unix_timestamp( '$endTime_benzhou' ) and jindu=1";
$rs01 = $pdo->query($sql01)->fetchColumn();
$week_num01 = $rs01;
//本周报价
$sql02 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benzhou' ) AND `jindushijian` <= unix_timestamp( '$endTime_benzhou' ) and jindu=2";
$rs02 = $pdo->query($sql02)->fetchColumn();
$week_num02 = $rs02;
//本周样品
$sql03 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benzhou' ) AND `jindushijian` <= unix_timestamp( '$endTime_benzhou' ) and jindu=3";
$rs03 = $pdo->query($sql03)->fetchColumn();
$week_num03 = $rs03;
//本周定金
$sql04 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benzhou' ) AND `jindushijian` <= unix_timestamp( '$endTime_benzhou' ) and jindu=5";
$rs04 = $pdo->query($sql04)->fetchColumn();
$week_num04 = $rs04;
//本周生产
$sql05 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benzhou' ) AND `jindushijian` <= unix_timestamp( '$endTime_benzhou' ) and jindu=6";
$rs05 = $pdo->query($sql05)->fetchColumn();
$week_num05 = $rs05;
?>
<?php
//本月询盘
$sql01 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benyue' ) AND `jindushijian` <= unix_timestamp( '$endTime_benyue' ) and jindu=1";
$rs01 = $pdo->query($sql01)->fetchColumn();
$month_num01 = $rs01;
//本月报价
$sql02 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benyue' ) AND `jindushijian` <= unix_timestamp( '$endTime_benyue' ) and jindu=2";
$rs02 = $pdo->query($sql02)->fetchColumn();
$month_num02 = $rs02;
//本月样品
$sql03 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benyue' ) AND `jindushijian` <= unix_timestamp( '$endTime_benyue' ) and jindu=3";
$rs03 = $pdo->query($sql03)->fetchColumn();
$month_num03 = $rs03;
//本月定金
$sql04 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benyue' ) AND `jindushijian` <= unix_timestamp( '$endTime_benyue' ) and jindu=5";
$rs04 = $pdo->query($sql04)->fetchColumn();
$month_num04 = $rs04;
//本月生产
$sql05 = "SELECT count(*) FROM jg_company where `jindushijian` >= unix_timestamp( '$beginTime_benyue' ) AND `jindushijian` <= unix_timestamp( '$endTime_benyue' ) and jindu=6";
$rs05 = $pdo->query($sql05)->fetchColumn();
$month_num05 = $rs05;
?>
<?php
//全部询盘
$sql01 = "SELECT count(*) FROM jg_company where jindu=1";
$rs01 = $pdo->query($sql01)->fetchColumn();
$all_num01 = $rs01;
//全部报价
$sql02 = "SELECT count(*) FROM jg_company where jindu=2";
$rs02 = $pdo->query($sql02)->fetchColumn();
$all_num02 = $rs02;
//全部样品
$sql03 = "SELECT count(*) FROM jg_company where jindu=3";
$rs03 = $pdo->query($sql03)->fetchColumn();
$all_num03 = $rs03;
//全部定金
$sql04 = "SELECT count(*) FROM jg_company where jindu=5";
$rs04 = $pdo->query($sql04)->fetchColumn();
$all_num04 = $rs04;
//全部生产
$sql05 = "SELECT count(*) FROM jg_company where jindu=6";
$rs05 = $pdo->query($sql05)->fetchColumn();
$all_num05 = $rs05;
?>