> I am building a hockey stats application.  I need to be able to allow 
> the user to enter in any 2-4 numbers.  I then need a way to convert 
> the 2-4 numbers into a time format.  Will the TimeFormat function do 
> this?  EX:  24 = 00:24    132 = 1:32   
> 
> I also need to subtract that time from another time to get the correct 
> score time.
> EX:  12:00 - 3:00 = 9:00      12:00 - 3:32 = 8:28

It's doable, although TimeFormat won't do it (it just formats times... you 
first have to convert your numbers to a time.)

I'f I'm reading your rules correctly (in that 132 is 1:32 AM and not 1:32 PM or 
132 minutes) then it should be easy.  Use the CreateTime() function - it takes 
the form:

CreateTime(hour, minute, second)

Take your input and pull the hours and minutes from it - always pass zero for 
seconds.

One simple way to do this is to first convert your input to four digits (it'll 
have to be a string, not number to maintain the otherwise insiginficant zeros). 
 I would append it to four zeros and then take the rightmost four characters.  
Something like (untested):

<cfset Input = "0000" & Input>
<cfset Input = Right(Input, 4)>

That will ensure that you're always dealing with four characters.  Now just 
pull off the first 2 as the "hour" and the second two as the "minute" and leave 
second as zero:

<cfset Hour = Left(Input, 2)>
<cfset Minute = Right(Input, 2)>
<cfset Second = 0>

Then create the time:

CreateTime(Hour, Minute, Second)

Now you have a "real" time and you can use TimeFormat to format it as you like.

This is all presented with the caveat that somebody else will appear as soon as 
I post with an infinitely more elegant, more understandable, and altogether 
better solution which will make me feel like an idiot.  I'll call this the 
"Davis Rule".  The corillary to the rule is that the other person may in fact 
be me.  ;^)

Hope this helps.

Jim Davis

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create Web Applications With ColdFusion MX7 & Flex 2. 
Build powerful, scalable RIAs. Free Trial
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJS 

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:282717
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to