• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 4年前 (2022-01-25) 26次浏览 已收录 0个评论

求解一个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].”
“;
}
?>

——解决方案——————–
$sql=”select count(*) from amp_test where date between ‘”.date(“Y-m-d”, ($tomorrow-/本2文来源[email protected]搞@^&代*@码2网搞gaodaima代码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’) = …来转换


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:求解一个php难题 是一个时间比较有关问题
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址