CFLib.org – Common Function Library Project

hoursMinutes(minutes)

Last updated July 2, 2008

author

Andrew Muller

Version: 2 | Requires: CF5 | Library: DateLib

Description:
Formats a number of minutes into "XX hours XX minutes".

Return Values:
Returns a string.

Example:

<cfset cookTime = "75">

<cfoutput>
Total cooking time: #HoursMinutes(cookTime)#
</cfoutput>

Parameters:

Name Description Required
minutes Number of minutes to convert to hours/minutes. Yes

Full UDF Source:

/**
 * Formats a number of minutes into &quot;XX hours XX minutes&quot;.
 * v2 Charlie Arehart found a bug if hours exactly 2, it said hour, not hours
 * 
 * @param minutes 	 Number of minutes to convert to hours/minutes. (Required)
 * @return Returns a string. 
 * @author Andrew Muller (rebel@daemon.com.au) 
 * @version 2, July 2, 2008 
 */
function hoursMinutes(minutes) {
	var tempstr = "";
	var strHours = minutes / 60;
	var strMinutes = minutes MOD 60;
	var hourText = "";
	if (strHours gte 1) {
		if (strHours gte 2) {
			hourText = " hours ";
		} else {
			hourText = " hour ";
		}
		tempstr = Fix(strHours) & hourText;
	}
	
	if (strMinutes gt 0) {
		tempstr = tempstr & strMinutes & " minutes";
	}
	return tempstr;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson