decimal2Time(decimal [, timeMask])
Last updated August 9, 2005
Version: 1 | Requires: ColdFusion 5 | 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:
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:
<cfscript>
/**
* 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;
}
</cfscript>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)