CFLib.org – Common Function Library Project

getCfDateTimeFromW3DateTime(dts)

Last updated August 2, 2006

Version: 1 | Requires: ColdFusion MX | Library: DateLib

 
Rated 2 time(s). Average Rating: 3.0

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:

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

Parameters:

Name Description Required
dts Datetime string. Yes

Full UDF Source:

view plain print about
<!---
 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

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson