decimal2Time(decimal[, timeMask])
Last updated August 09, 2005
Version: 1 | Requires: CF5 | Library: DateLib
Description:
Takes a decimal value between 0.001 and 23.99 and converts it to a time format.
Return Values:
Returns a string.
Example:
<cfoutput>#decimal2Time(15.25)#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
decimal | A number between 0 and 23.99. | Yes |
timeMask | Mask for formatting. Defaults to hh:mm tt. | No |
Full UDF Source:
/**
* Converts decimal to time.
*
* @param decimal A number between 0 and 23.99. (Required)
* @param timeMask Mask for formatting. Defaults to hh:mm tt. (Optional)
* @return Returns a string.
* @author Nick Giovanni (audi.tt@verizon.net)
* @version 1, August 9, 2005
*/
function decimal2Time(decimal){
var timeMask = "hh:mm tt";
var timeValue = "";
var decimalMinutes = "";
var decimalHours = "";
//make sure passed value is numeric
if(not isNumeric(decimal)) return "The value passed to function decimalToTime() is not a valid number!";
timeValue = numberFormat(decimal,"99.99");
if(timeValue LT 0 OR timeValue GTE 24) return "The value passed to function decimalToTime() is not within the valid range of 0 - 23.99";
//if the optional mask was passed use that otherwise default to "hh:mm tt"
if(arrayLen(arguments) gt 1) timeMask = arguments[2];
decimalHours = listfirst(timeValue,".");
decimalMinutes = listLast(timeValue,".");
//attempt to determine minutes
if(decimalMinutes neq 0) decimalMinutes = round(60*decimalMinutes/100);
timeValue = timeFormat(decimalHours & ":" & decimalMinutes,timeMask);
return timeValue;
}
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