That's a nice method Jim. -----Original Message----- From: Jim Davis [mailto:[EMAIL PROTECTED] Sent: Monday, July 02, 2007 10:43 AM To: CF-Talk Subject: Re: Time Question
> 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| CF 8 â Scorpio beta now available, easily build great internet experiences â Try it now on Labs http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_adobecf8_beta Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:282722 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4