日期:2014-05-17  浏览次数:20407 次

求解一个php难题 是一个时间比较问题
总是出的数据是0,是不是需要转换一下数据格式啊 数据库时间是年:月:日 小时分秒 ,我是不是需要转成年月日啊,关键是如何转换啊 小弟亏求
<?php
for ($i = 0; $i < 30; $i++) {
$tomorrow = mktime(0,0,0,date("m"),date("d")-$i,date("Y"));
$sql="select count(*) from customers_info where customers_info_date_account_created='".date("Y-m-d", $tomorrow)."'";
$result=mysql_query($sql,$conn) or
die("Error:".mysql_error);
$row=mysql_fetch_row($result);
echo $row[0]."<br>";
}
?>



------解决方案--------------------
$sql="select count(*) from amp_test where date between '".date("Y-m-d", ($tomorrow-3600*24))."' and '".date("Y-m-d", $tomorrow)."'";
输出:
1257292800select count(*) from amp_test where date between '2009-11-03' and '2009-11-04'2
1257206400select count(*) from amp_test where date between '2009-11-02' and '2009-11-03'1
1257120000select count(*) from amp_test where date between '2009-11-01' and '2009-11-02'0 
我测试用的数据库里的格式是timestamp , 2009-11-04 11:13:25这种
------解决方案--------------------
可以使用DATE_FORMAT(your_field, '%Y-%m-%d') = ...来转换