假设我在数据库内插入的订单创建时间字段是用的10位数的unix时间戳,我想查询今天的所有订单,例如:
select count() where后面不会了
不知道如何操作了!
后面的条件该怎么写?
解决方案:
$todayzero = strtotime(date('Y-m-d',time()));
//return $todayzero;
//今日访问量
$today = pdo_fetchcolumn('select count(*) from '.tablename('wc_nongplus_count'). "where uniacid=:uniacid and (createtime>=$todayzero and createtime<=:createtime)",array(':uniacid'=>$uniacid,':createtime'=>time()));
//总访问量
$counts = pdo_fetchcolumn('select count(*) from '.tablename('wc_nongplus_count'). "where uniacid=:uniacid",array(':uniacid'=>$uniacid));
time<当前时间戳 and time > 今天凌晨时间戳-1
查询其他日期的同理
time<日期结束次日凌晨时间戳 and time > 日期开始凌晨时间戳-1
建议增加一个冗余字段 day 20190320 这种格式的 这种格式的话进行查询压力要小特别多
今天00:00
$todaystart = strtotime(date(‘Y-m-d’.’00:00:00′,time()));
今天24:00
$todayend = strtotime(date(‘Y-m-d’.’00:00:00′,time()+3600*24));
select count() where ctime > $todaystart and ctime < $todayend
select count(*) from orders where createdate>UNIX_TIMESTAMP(CAST(SYSDATE()AS DATE))