Home  >  Article  >  Backend Development  >  php依据时间段查询每天的数据

php依据时间段查询每天的数据

WBOY
WBOYOriginal
2016-06-13 12:26:051250browse

php根据时间段查询每天的数据
现在需要查询给定的日期内的每天的数据,请教各位有没有什么好的办法?
------解决思路----------------------
你可以看看MYSQL的日期函数,比如你保存时间戳的字段为t
可以这样统计数据
SELECT COUNT(*) AS n,FROM_UNIXTIME(`t`,'%y-$m-%d') AS d FROM `tb` GROUP BY d ORDER BY d
不过这种效率很低,最好你插入的时候就计算好日期。
------解决思路----------------------

<br /><?php <br />///$ary为该时间区间下所有的数据<br /><br />foreach($ary as $k=>$v)<br />{	$datas['day_'.date('md',$v['timestamp'])][]=$v;//分组<br />	<br />	}<br /><br />var_dump($datas['day_0809'])//为8月9号那天所有数据;<br />?><br />

------解决思路----------------------
时间戳有时间戳的好处
用php来做数据整合就可以咯.
------解决思路----------------------
每种数据库的日期时间函数都是不一样的
如果你有升迁到大型或分布式数据库的打算时,则一定不能使用日期、时间类型字段
使用 unix 时间戳可免除绝大多数日期时间函数的烦恼

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn