Passing dates to cfc?
I'm just starting to write cfcs and I am a bit puzzled by why my dates don't work if I pass them through an argument, but they work fine if I put the date in directly as a variable (todayDate).
The date is set at the top of the page<cfset todayDate = CreateODBCDate(now())>. The intention is to use a form to pass the dates, however it didn't work so I am simplifying with a default date to try and find the problem.
This works:
<cffunction name="getTimeReport" returntype="query">
<cfargument name="UserRole" default="2" required="no">
<cfargument name="UserID" default="#session.Username#" required="yes" type="string">
<cfargument name="StartDate" default="#todayDate#" required="yes" type="date">
<cfargument name="EndDate" default="#todayDate#" required="yes" type="date">
<cfargument name="GroupBy" default="activityID" required="no">
<cfquery datasource="#application.ds#" name="getSumTime">
SELECT #Arguments.GroupBy#, SUM(time) AS TotalTime
FROM mydb
WHERE userID = '#Arguments.UserID#'
AND entrydate >= #todayDate# AND entrydate <= #todayDate#
GROUP BY #Arguments.GroupBy#
</cfquery>
<cfreturn getSumTime>
</cffunction>
This doesn't:
<cffunction name="getTimeReport" returntype="query">
<cfargument name="UserRole" default="2" required="no">
<cfargument name="UserID" default="#session.Username#" required="yes" type="string">
<cfargument name="StartDate" default="#todayDate#" required="yes" type="date">
<cfargument name="EndDate" default="#todayDate#" required="yes" type="date">
<cfargument name="GroupBy" default="activityID" required="no">
<cfquery datasource="#application.ds#" name="getSumTime">
SELECT #Arguments.GroupBy#, SUM(time) AS TotalTime
FROM mydb
WHERE userID = '#Arguments.UserID#'
AND entrydate >= #Arguments.StartDate# AND entrydate <= #Arguments.EndDate#
GROUP BY #Arguments.GroupBy#
</cfquery>
<cfreturn getSumTime>
</cffunction>
Any ideas? I am pretty bad at spotting obvious errors so I'd appreciate any pointers. I tried different date formats but I don't think that's the problem, I just can't seem to pass it through the arguments. The other arguments are passing through ok.
Neve
