sql datediff问题
我正在尝试计算两个日期(当前日期和我的会员在网站上订阅的日期)之间的差异。如果差异超过 30 天,我就会关闭他们的订阅。我就是无法让它发挥作用。
$strFind="SELECT DATEDIFF(date, curdate()) AS total FROM `monthlydues` WHERE `memid`=\"$curmemid\" ORDER BY `id` DESC LIMIT 1";
$result=mysql_query($strFind) or die(mysql_error());
$row=mysql_fetch_array($result);
$gtime=$row['total'];
if($gtime>30){
$strsql="UPDATE monthlydues SET `active`='N' WHERE `memid`=\"$curmemid\"";
mysql_query($strsql,$connect) or die(mysql_error());
$chkrow5=mysql_affected_rows($connect);
}
I'm trying to calculate the difference between 2 dates, the current date and the date my members subscribed on the site. If the difference is more than 30 days, I turn off their subscription. I just can't get it to work.
$strFind="SELECT DATEDIFF(date, curdate()) AS total FROM `monthlydues` WHERE `memid`=\"$curmemid\" ORDER BY `id` DESC LIMIT 1";
$result=mysql_query($strFind) or die(mysql_error());
$row=mysql_fetch_array($result);
$gtime=$row['total'];
if($gtime>30){
$strsql="UPDATE monthlydues SET `active`='N' WHERE `memid`=\"$curmemid\"";
mysql_query($strsql,$connect) or die(mysql_error());
$chkrow5=mysql_affected_rows($connect);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不发表一份声明?
那么这个?
Why not one statement?
So this?
您必须指定您想要什么样的差异。
例如,对于 SQL Server,您可以像这样指定天数差异:
You have to specify what kind of difference you want.
For SQL Server for example you specify a difference in days like this:
以下内容可能会对您有所帮助,但这具体取决于您想要做什么;此查询将对所有成员进行操作,而不仅仅是由指定 id 标识的成员:
如果您希望针对特定成员,只需添加一个约束:
编辑: NOW() 是一个 MySQL 函数。在差异引擎上可能会有所不同
The following may help you, though it depends on exactly what you want to do; This query will operate on all members, not just the member identified by a specified id:
If you wish to target a specific member, simply add a constraint:
EDIT: NOW() is a MySQL function. Is likely to be different on diff engines