Brilliant- that's got it, thanks. Can't really believe I've never hit that error in the past 6 years... :)
Cheers! T On 18 August 2010 13:48, Jason Fisher <[email protected]> wrote: > > It's because you re-used the variable names startDate and endDate, so you > re-wrote the value of each variable to strip out the time and then asked > for the time. Always be sure to 'var' all variables in a function, and > you'll avoid the snafu. If you do the following, you'll even get a runtime > error letting you know the problem (cannot var a variable with the same > name as an argument): > > > > <cffunction name="dateFormatter2" returntype="string" access="private" > output="No"> > <cfargument name="startDate" type="date" required="Yes" /> > <cfargument name="endDate" type="date" required="Yes" /> > > <cfscript> > var result = ""; > var startDate = ""; > var startTime = ""; > var endDate = ""; > var endTime = ""; > > startDate = dateFormat(arguments.startDate, "dd mmmm yyyy"); > startTime = timeFormat(arguments.startDate, "HH:mm"); > endDate = dateFormat(arguments.endDate, "dd mmmm yyyy"); > endTime = timeFormat(arguments.endDate, "HH:mm"); > </cfscript> > > <cfsavecontent variable="result"> > <cfoutput> > Start: #startDate#, #startTime# > <br />End: #endDate#, #endTime# > </cfoutput> > </cfsavecontent> > > <cfreturn result /> > </cffunction> > > > <cfoutput> > #dateFormatter2(now(), now())# > </cfoutput> > > > Use different var names, and it works fine: > > > > <cffunction name="dateFormatter2" returntype="string" access="private" > output="No"> > <cfargument name="startDate" type="date" required="Yes" /> > <cfargument name="endDate" type="date" required="Yes" /> > > <cfscript> > var result = ""; > var start = ""; > var startTime = ""; > var end = ""; > var endTime = ""; > > start = dateFormat(arguments.startDate, "dd mmmm yyyy"); > startTime = timeFormat(arguments.startDate, "HH:mm"); > end = dateFormat(arguments.endDate, "dd mmmm yyyy"); > endTime = timeFormat(arguments.endDate, "HH:mm"); > </cfscript> > > <cfsavecontent variable="result"> > <cfoutput> > Start: #start#, #startTime# > <br />End: #end#, #endTime# > </cfoutput> > </cfsavecontent> > > <cfreturn result /> > </cffunction> > > > <cfoutput> > #dateFormatter2(now(), now())# > </cfoutput> > > > > ---------------------------------------- > > From: "Tom King" <[email protected]> > Sent: Wednesday, August 18, 2010 8:26 AM > To: "cf-talk" <[email protected]> > Subject: Passing a Date Time Value to a function > > It's been one of those days already - can anyone tell me why the time gets > stripped out? I'm aware that I'm using 'date' as an argument type, but > datetime throws an error and there's nothing in CF8 docs on it... How do I > preserve the time data? > > <cffunction name="dateFormatter2" returntype="string"> > <cfargument name="startDate" type="date"> > <cfargument name="endDate" type="date"> > <cfscript> > var result =""; > startDate=dateFormat(arguments.startdate, 'dd mmmm yyyy'); > startTime=timeFormat(arguments.startdate, "HH:MM"); > endDate=dateFormat(arguments.enddate, 'dd mmmm yyyy'); > endTime=timeFormat(arguments.enddate, "HH:MM"); > </cfscript> > > <cfsavecontent variable="result"> > <cfoutput>Start: #startDate#, #startTime# <br />End: #endDate#, > #endTime#</cfoutput> > </cfsavecontent> > <cfreturn result> > </cffunction> > > <cfoutput> > #dateFormatter2(now(),now())# > </cfoutput> > > Cheers! > T > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336351 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

