[英]Get rows within 30 days where year is current year, month is current month, day is a string
我一直在編寫一個代碼來計算在客戶端刷新日期的 30 天內構建了多少個鏈接,構建的鏈接將被存檔。
我一直在與下面的代碼斗爭幾個小時,試圖讓它只選擇日期在“刷新日”、當前月份和當前年份 30 天內的行。
我的“刷新日期”列是這樣布局的:2017-01-11 00:00:00
進行查詢的最佳方法是什么?
$fulldate = $row["refreshdate"];
$prcount= mysql_query("SELECT linkid FROM linksbuilt WHERE clientid = '$clientid' and linktype = 'PR' and DATEDIFF(day,'$fulldate',getdate()) < 31 ");
您的問題被標記為“mysql”,並且您使用的是 MySQL 界面(盡管過時且不再受支持 - 切換到mysqli_
)。 那么,為什么要使用 SQL Server 約定?
我認為你想要的查詢是:
SELECT linkid
FROM linksbuilt
WHERE clientid = '$clientid' and
linktype = 'PR' and
'$fulldate' >= datesub(now(), interval 30 days);
哦,我有沒有提到你應該使用“mysqli_”接口並在查詢中使用常量參數,而不是修改查詢字符串。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.