<CFSET TodaysDate = #DateFormat (Now(), "mm-dd-yyyy")#>
<CFSET CheckDate = #DateFormat(TodaysDate-14,"mm-dd-yyyy")#>
<cfquery name="getUser" datasource="DNS_Test">
select *
from Login
where DateEntered <= #CheckDate#
</cfquery>
<cfoutput>
<cfloop QUERY="getUser">
#getUser.LastName#, #getUser.FirstName# <br>
<cfloop>
</cfoutput>
答案 0 :(得分:14)
您需要使用DateAdd()
。
示例:从不use select *
,而是使用列名...也使用<cfqueryparam>
SELECT LastName, FirstName
FROM Login
WHERE DateEntered <= <cfqueryparam value="#DateAdd( 'd', -14, now() )#" CFSQLType="CF_SQL_DATE">
答案 1 :(得分:1)
您可能还想在SQL中进行计算。例如,在SQL Server中:
SELECT LastName, FirstName
FROM Login
WHERE DateEntered <= CONVERT(date,
DateAdd(dd, <cfqueryparam value="-14" CFSQLType="CF_SQL_INTEGER">,
getDate())
)
如果DateEntered具有hh:mm:ss
,则可能需要进行一些调整