user460114
user460114

Reputation: 1851

coldfusion - parsing a string date into datetime format

We receive an XML file with a date node as follows:

<createdDate>1/11/2008 7:04:28 a.m.</createdDate>

Dates are UK format dd/mm/yyy, so 1/11/2008 is 1st November 2008.

We run a coldfusion function to parse the xml and insert into the database. The relevant database field is of datetime datatype and needs to remain that way. How would I format this string representation of the date into a format the database will accept?

Upvotes: 1

Views: 5721

Answers (1)

CFML_Developer
CFML_Developer

Reputation: 1605

Not an ideal situation, but the format you are getting data especially dots in am/pm strings make it hard to read and on top of that it comes in UK Date format. This can help:

<cfset x="21/11/2008 7:04:28 p.m.">
<cfset x=Replace(x,".","","All")>
<cfset y=LSDateFormat(x,"mm/dd/yyyy","English (UK)")>
<cfoutput>
    x====#x#
    <br/>y===#y#
<cfset z=CreateDateTime(Year(y),month(y),day(y),hour(x),minute(x),second(x))>
z====#z#
<cfset someDatevare=LSParseDateTime(x,"English (UK)")>
</cfoutput>


EDIT As Leigh mentioned, removing periods or any other non-standard characters from the string and then LSParseDateTime will return a date time object.

Upvotes: 2

Related Questions