CFLib.org – Common Function Library Project

getCfDateTimeFromW3DateTime(dts)

Last updated August 2, 2006

author

Jared Rypka-Hauer

Version: 1 | Requires: CF6 | Library: DateLib

Description:
Converts string representation of a W3 date and returns a CF datetime, will handle GMT+, GMT-, and Z.

Return Values:
Returns a date.

Example:

<cfset dts = "(2006-07-29T23:59:00Z)">
<cfoutput>#getCfDateTimeFromW3DateTime(dts)#</cfoutput>

Parameters:

Name Description Required
dts Datetime string. Yes

Full UDF Source:

<!---
 Takes a W3 date and returns a CF datetime.
 
 @param dts 	 Datetime string. (Required)
 @return Returns a date. 
 @author Jared Rypka-Hauer (jared@web-relevant.com) 
 @version 1, August 2, 2006 
--->
<cffunction name="getCfDateTimeFromW3DateTime" access="public" returntype="string" output="false">
    <cfargument name="dts" type="string" required="true" />
    <cfif left(dts,1) is "(">
        <cfset dts = mid(dts,2,len(dts)-2)>
    </cfif>
    <cfset dts = listToArray(reReplace(dts,"(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\D)?(\d{2})?(:00)?","\2/\3/\1 \4:\5:\6;\7;\8"),";")>
    <cfif arrayLen(dts) IS 2>
        <cfreturn createDateTime(year(dts[1]),month(dts[1]),day(dts[1]),hour(dts[1]),minute(dts[1]),second(dts[1])) />
    <cfelse>
        <cfif dts[2] is "-">
            <cfreturn dateAdd("h",0-listFirst(dts[3],":"),dts[1]) />
        <cfelse>
            <cfreturn dateAdd("h",listFirst(dts[3],":"),dts[1]) />
        </cfif>
    </cfif>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson