Wordpress magazine themes - Debt Consolidation - Debt Consolidation - Debt Consolidation - Debt Consolidation

PDA

View Full Version : String to date conversion


youjie
Nov 15th 2006, 1:26 am
Hi anyone knows how to convert a string to a date variable in coldfusion?

i have a string "200611" which is in yyyymm format andi wish to convert it into a date variable of yyyymm format

thanks in advance ...

seamus.hogan
Nov 15th 2006, 2:17 am
Hi youjie,

you could try this.

<!--- set the date string --->
<cfset input = "200611">

<!--- extract the first 4 characters from the string --->
<cfset yearpart = mid(input, 1,4)>

<!--- extract the last 2 characters from the string --->
<cfset monthpart = mid(input, 5,2)>

<!--- create a date using the two parts --->
<cfset date = createdate(yearpart, monthpart, 01)>

<!--- output the date with the formatting --->
<cfoutput>#dateformat(date, 'yyyy/mm')#</cfoutput>

Hope this helps