CFLib.org – Common Function Library Project

hoursMinutes(minutes)

Last updated July 2, 2008
Download UDF

author

Andrew Muller Andrew Muller

Version: 2 | Requires: ColdFusion 5 | Library: DateLib

 
Rated 0 time(s). Average Rating: 0

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:

<cfscript>
/**
* 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;
}
</cfscript>

Search CFLib.org


Latest Additions

Shawn Porter Shawn Porter added
DeMoronize
3 hour(s) ago

Chris Carey Chris Carey added
readPropertiesFi...
1 day(s) ago

Randy Johnson Randy Johnson added
lastDayofWeek
3 day(s) ago

Frank Marion Frank Marion added
sitemapPing
7 day(s) ago

Top Rated

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Barney Boisvert indentXml
Rated 5.0, 3 time(s)

Nathan Dintenfass                                 queryColumnsToSt...
Rated 5.0, 3 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson