Home > Backend Development > PHP Tutorial > 求解一个php难题 是一个时间比较有关问题

求解一个php难题 是一个时间比较有关问题

WBOY
Release: 2016-06-13 13:39:09
Original
766 people have browsed it

求解一个php难题 是一个时间比较问题
总是出的数据是0,是不是需要转换一下数据格式啊 数据库时间是年:月:日 小时分秒 ,我是不是需要转成年月日啊,关键是如何转换啊 小弟亏求
for ($i = 0; $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]."
";
}
?>



------解决方案--------------------
$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') = ...来转换

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template