tnoe0131
asked on
Coldfusion: TimeFormat to Float
Hi,
I have the following:
<cfset myStartTime = TimeFormat(#rsGetAssignmen t.ASS_STAR TTIME#,'hh :mm:ss tt')>
<cfset myEndTime = TimeFormat(#FORM.CheckOutT ime#,'hh:m m:ss tt')>
<cfset myHours = TimeFormat(#myEndTime# - #myStartTime#,'hh:mm')>
myHours gives the the right answer in hh:mm format. However, I need to convert this to a decimal to put into a Float field in my MS SQL database.
For example, if I get myHours to be 07:30, I need it to be 7.5.
Any suggestions? I'm a newbie, so be gentle... ha ha.
Thanks,
Todd
I have the following:
<cfset myStartTime = TimeFormat(#rsGetAssignmen
<cfset myEndTime = TimeFormat(#FORM.CheckOutT
<cfset myHours = TimeFormat(#myEndTime# - #myStartTime#,'hh:mm')>
myHours gives the the right answer in hh:mm format. However, I need to convert this to a decimal to put into a Float field in my MS SQL database.
For example, if I get myHours to be 07:30, I need it to be 7.5.
Any suggestions? I'm a newbie, so be gentle... ha ha.
Thanks,
Todd
as a short cut you can skip all those lines of code and just to this:
<cfoutput>#datediff("n",#r sGetAssign ment.ASS_S TARTTIME,F ORM.CheckO utTime)/60 #</cfoutpu t>
<cfoutput>#datediff("n",#r
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would suggest using date functions to calculate the value.
<cfset floatHours = dateDiff("n", myStartTime, myEndTime) / 60 >
<cfoutput>#floatHours#</cf output>
<cfset floatHours = dateDiff("n", myStartTime, myEndTime) / 60 >
<cfoutput>#floatHours#</cf
>> <cfset floatHours = dateDiff("n", myStartTime, myEndTime) / 60 >
looks like the exact same solution I just posted 2 mins earlier:
datediff("n",rsGetAssignme nt.ASS_STA RTTIME,FOR M.CheckOut Time)/60
looks like the exact same solution I just posted 2 mins earlier:
datediff("n",rsGetAssignme
Oops. I see some more comments were added.
> <cfset myEndTime = TimeFormat(#FORM.CheckOutT ime#,'hh:m m:ss tt')>
TimeFormat() doesn't really do much here since it returns a string _not_ a datetime object. In other words, you're just converting a string to another string. If you're going to do any type of validation/conversion better to parse the values into datetime objects instead, then use the datetime objects in your function.
<cfset floatHours = dateDiff("n", myStartTimeObject, myEndTimeObject) / 60 >
> <cfset myEndTime = TimeFormat(#FORM.CheckOutT
TimeFormat() doesn't really do much here since it returns a string _not_ a datetime object. In other words, you're just converting a string to another string. If you're going to do any type of validation/conversion better to parse the values into datetime objects instead, then use the datetime objects in your function.
<cfset floatHours = dateDiff("n", myStartTimeObject, myEndTimeObject) / 60 >
SBennett,
All I saw when I was posting was a comment about using string functions. I thought of a better solution and posted it. Obviously you must have had a similar thought since you posted a different solution a few minutes later. Welcome to the stateless nature of the web. ;)
All I saw when I was posting was a comment about using string functions. I thought of a better solution and posted it. Obviously you must have had a similar thought since you posted a different solution a few minutes later. Welcome to the stateless nature of the web. ;)
ASKER
_agx_ and SBennet - I appreciate both of your answers - and how fast you responded - it's working beautifully now!
<cfset myHours = "07:30">
<cfset decimalhours = listgetat(myHours,1,":") + (listgetat(myHours,2,":")/
<cfoutput>#decimalhours#</