Convert hours to minutes and minutes to hours

There are no predefined functions in CFML for this, so we have to write some lines of code.

The code:

<cfset tot_minutes = "145">
<!--- Convert to h/m --->
<cfset hours = int(tot_minutes/60)>
<cfset minutes = int(tot_minutes MOD 60)>

<cfoutput>#tot_minutes# minutes: #hours# hours and #minutes# minutes.</cfoutput>

<br>

<!--- Convert back to minutes --->
<cfset tot_minutes_back = (hours * 60) + minutes>

Total minutes: <cfoutput>#tot_minutes_back#</cfoutput>

The output:

145 minutes: 2 hours and 25 minutes.
Total minutes: 145

Advertisement

User Comments: 1

 Converting minutes to hours....

how do I convert minutes to hours by using a simple dividing technique?
Sample: 150 minutes = 2 1/2 hours.

I can do that one in my head (!!) but if it comes to larger numbers, this becomes more difficult...
We need an answer that breaks down to hours and then 1/4, 1/2 and 3/4 hours.
What simple way is there to do that?

ApplayIT is owned by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.