CFLib.org – Common Function Library Project

hoursMinutes(minutes)

Last updated July 02, 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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson