能够得到这样格式的时间 2008-12-03 2007-11-13。 编写sql语句实现这样几个统计信息: 今日统计:slect * from a where 时间是今天(怎么表达) 本月统计:slect * from a where 时间是本月(怎么表达) 今年统计:slect * from a where 时间是今年(怎么表达)
今日统计:"slect * from a where tempDate='".date("Y-m-d")."'" 本月统计:"slect * from a where MONTH(tempDate)='".date("m")."'" 今年统计:"slect * from a where YEAR(tempDate)='".date("Y")."'"
楼主的意思也就是要实现按时间查询表中内容:1.在建表的时候要把数据存入数据库的日期记入库中,假如记为year,mon,date;2.存入数据库前计算今天的时间:$year=date('Y');$mon=date('n');$date=date('j');具体时间不用管了3.在统计数据的时候就可以实现楼主想要的效果了:在查询之前,计算现在的 $year,$mon,$date,计算方法同上!今日统计:slect * from a where date=$date; 本月统计:slect * from a where mon=$mon; 今年统计:slect * from a where year=$year;
今日统计:"slect count(*) as countnum from a where tempDate='".date("Y-m-d")."'" 本月统计:"slect count(*) as countnum from a where MONTH(tempDate)='".date("m")."'" 今年统计:"slect count(*) as countnum from a where YEAR(tempDate)='".date("Y")."'" tempDate为你表中的时间字段。
不好意思,上面的本月统计漏了个条件:"slect * from a where MONTH(tempDate)='".date("m")."' and YEAR(tempDate)='".date("Y")."'"
select date_format(now(),get_format(date,'iso')) as date;
date("Y-m-d")得到的时间是今天,昨天该如何表达?
昨天的: $sql = 'slect * from a where tempDate=DATE_SUB('.date("Y-m-d").',INTERVAL 1 DAY)'
先计算出昨天的日期: $time=time()-24*60*60; //昨天的时期戵$date=date('Y-m-d',$time); //昨天的格式后日期 昨日统计:"slect * from a where tempDate='".$date."'"
编写sql语句实现这样几个统计信息:
今日统计:slect * from a where 时间是今天(怎么表达)
本月统计:slect * from a where 时间是本月(怎么表达)
今年统计:slect * from a where 时间是今年(怎么表达)
本月统计:"slect * from a where MONTH(tempDate)='".date("m")."'"
今年统计:"slect * from a where YEAR(tempDate)='".date("Y")."'"
本月统计:slect * from a where mon=$mon;
今年统计:slect * from a where year=$year;
今日统计:"slect count(*) as countnum from a where tempDate='".date("Y-m-d")."'"
本月统计:"slect count(*) as countnum from a where MONTH(tempDate)='".date("m")."'"
今年统计:"slect count(*) as countnum from a where YEAR(tempDate)='".date("Y")."'"
tempDate为你表中的时间字段。
不好意思,上面的本月统计漏了个条件:"slect * from a where MONTH(tempDate)='".date("m")."' and YEAR(tempDate)='".date("Y")."'"
$sql = 'slect * from a where tempDate=DATE_SUB('.date("Y-m-d").',INTERVAL 1 DAY)'
$time=time()-24*60*60; //昨天的时期戵$date=date('Y-m-d',$time); //昨天的格式后日期
昨日统计:"slect * from a where tempDate='".$date."'"