本文介绍了如何在php中获取更新日期小于30天的所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从 mysql 数据库中获取从当前日期起 30 天内更新记录的所有记录,因为我使用了以下查询,但它无法正常工作.$tda 是当前日期,$prevmonth 是确切日期从当前日期回溯 30 天.请帮忙.谢谢.
I want to get all the records from mysql database who have updated their records within 30 days from the current date for that i have used the below query but it is not working properly. $tda is the current date and $prevmonth is the date of exactly 30 days back from the current date. Please help. Thanks.
$da=date('d'); $tda=date('d-m-Y'); $prevmonth = date(''.$da.'-m-Y', strtotime('-1 months')); $sql_q=executeQuery("select * from ".reg." where 'uid' !=".$_SESSION['uid']." AND Updatedate >= '$prevmonth' AND Updatedate <='$tda '"); 推荐答案你可以在mysql中做
You can do it in mysql as
`Updatedate` < DATE(NOW() - INTERVAL 30 DAY)或
`Updatedate` < DATE_SUB(CURDATE(), INTERVAL 30 DAY)对于 Varchar
For Varchar
STR_TO_DATE(Updatedate, '%Y-%m-%d') < DATE_SUB(CURDATE(), INTERVAL 30 DAY)更新:
评论中发布的查询是错误的,应该是
The query posted in the comment is wrong and should be
$sql_q=executeQuery("select * from registration where `uid` != ".$_SESSION['uid']." AND STR_TO_DATE(Update_date, '%d-%m-%Y') < DATE_SUB(CURDATE(), INTERVAL 30 DAY)") ;如果您要查找过去 30 天内的数据,则
If you are looking for data within last 30 days then
$sql_q=executeQuery("select * from registration where `uid` != ".$_SESSION['uid']." AND STR_TO_DATE(Update_date, '%d-%m-%Y') >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)") ;更多推荐
如何在php中获取更新日期小于30天的所有记录
发布评论