Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need function to convert time

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a problem. I am writing a program, where a user enters 2 times in the URL. The format is 4 digit (ex: 0930, or 1650). Need to be able to determine the travel time and output it in an hours and minutes format? can anyone help.
 
If you mean that you are looking to calculate the difference between two times on the same day, I think this will do what you want. This assumes your two time variables are time1 and time2.

<cfset x = datediff(&quot;n&quot;,&quot;1/1/2000 #left(time1,2)#:#right(time1,2)#:00&quot;,&quot;1/1/2000 #left(time2,2)#:#right(time2,2)#:00&quot;>

<cfset hours=int(x/60)>
<cfset minutes=x-(60*hours)>

I didn't test it so let me know if you have any problems,
GJ
 
That worked great, Thank You. One more quick question, how can I display the URL entered time 0920 as 9:20?
 
I think this will work for you.

#timeformat(&quot;#left(time1,2)#:#right(time1,2)#:00&quot;,&quot;hh:mm&quot;)#

GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top