CFLib.org – Common Function Library Project

getSecondsFromTime(timeObject)

Last updated July 16, 2008
Download UDF

author

Alan McCollough Alan McCollough

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

Description:
Returns the total number of seconds from midnight for a valid date/time object.

Return Values:
Returns a numeric value.

Example:

<CFSET TheTime=Now()>

<CFOUTPUT>
Given a time of #TimeFormat(TheTime)#<BR>
#GetSecondsFromTime(TimeFormat(TheTime))# seconds have elapsed since midnight.
<P>
Given a time of #TheTime#<BR>
#GetSecondsFromTime(TheTime)# seconds have elapsed since midnight.
</CFOUTPUT>

Parameters:

Name Description Required
timeObject Valid date/time object. Yes

Full UDF Source:

<cfscript>
/**
* Returns the total number of seconds from midnight for a valid date/time object.
* Note that this function returns different results depending on whether the date/time object you pass it has seconds defined.
*
* v2 bug fix by Steven Van Gemert
*
* @param timeObject      Valid date/time object. (Required)
* @return Returns a numeric value.
* @author Alan McCollough (kittycat@kittycatonline.com)
* @version 2, July 16, 2008
*/

function getSecondsFromTime(timeObject){
var theSeconds = Val(Hour(timeObject) * 3600) + Val(Minute(timeObject) * 60) + Second(timeObject);
return theSeconds;
}
</cfscript>

Search CFLib.org


Latest Additions

Topper Topper added
getCurrentURL
1 hour(s) ago

Daniel Chicayban Daniel Chicayban added
IsListInList
1 day(s) ago

Jeff Howden Jeff Howden added
CSVFormat
9 day(s) ago

Tom de Manincor Tom de Manincor added
flattenStruct
10 day(s) ago

Troy Pullis Troy Pullis added
iCalUS
10 day(s) ago

Created by Raymond Camden / Design by Justin Johnson