2011-04-26 67 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