2011-04-26 116 views
0

任何人都可以幫助我以下嗎?php mysql where where clause使用日期

$crDate = date("Y-m-d"); 
$sql="update callrecord set crEndtime = Now() where crUsId = ".$crUsId."AND crDate = ".$crDate; 

我試圖做的是更新表「callrecord」其中crDate是當前日期。當我把部分拿出來時,它工作正常。

$sql="update callrecord set crEndtime = Now() where crUsId = ".$crUsId; 

這工作正常。但我想查看當前的日期。任何幫助?

+0

您通常會將日期輸入爲字符串,因此您需要引用它。例如'SELECT * FROM Orders WHERE OrderDate ='2008-11-11';'[Source](http://www.w3schools.com/SQl/sql_dates.asp)here。日期時間是'2008-11-11 03:29:12'; – styfle 2011-04-26 01:35:08

回答

3

你可以使用MySQL函數curdate()而不用在php中計算它。

$sql = "update callrecord set crEndtime = Now() 
     where crUsId = '$crUsId' AND crDate = curdate()"; 
+0

dint工作... :( – Phphelp 2011-04-26 01:36:17

+0

對不起我的錯誤..它工作..謝謝.. :) – Phphelp 2011-04-26 01:37:53

0

我想你應該嘗試使用單引號環繞$ crDate。

+0

dint工作... :( – Phphelp 2011-04-26 01:36:42

+0

非常感謝... :) – Phphelp 2011-04-26 01:38:26