这是我的查询
SELECT
StudentID, DateRegistered
FROM
StudentTable
WHERE
DateDiff(day, DateRegistered, '" & Date.Now & "') <= 7
答案 0 :(得分:1)
你没有标记你的RDBMS,每个人都有不同的日期功能,但其中一个应该可以正常工作:
SELECT StudentID, DateRegistered
FROM StudentTable
WHERE DateDiff(day, DateRegistered, now()) <= 7
或者
WHERE DateDiff(day, DateRegistered, getdate()) <= 7
或者这个:
CURDATE()
请注意,我使用本地DBMS选择日期,不需要在PHP端使用参数进行此操作。
答案 1 :(得分:0)
日期应该在&#34; YYYY-MM-dd&#34;格式。
SELECT
StudentID, DateRegistered
FROM
StudentTable
WHERE
DateDiff(day, DateRegistered, '" & DateTime.Now.ToString('yyyy-MM-dd') & "') <= 7
答案 2 :(得分:0)
cmd = "SELECT StudentID, DateRegistered
FROM StudentTable
WHERE DateRegistered between @startdate and @enddate", connectionstring)
cmd.parameters.addwithvalue("@StartDate",today.date.subtract(timespan.fromdays(7)))
cmd.parameters.addwithvalue("@EndDate",today)