求解一個php難題 是一個時間比較有關問題

來源:互聯網
上載者:User
求解一個php難題 是一個時間比較問題
總是出的資料是0,是不是需要轉換一下資料格式啊 資料庫時間是年:月:日 小時分秒 ,我是不是需要轉成年月日啊,關鍵是如何轉換啊 小弟虧求
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-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') = ...來轉換
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.