Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting string to date

Status
Not open for further replies.

olmos

Technical User
Oct 25, 2000
135
US
I am having trouble converting a string which is
is a date such as 050419 (yymmdd) to a dateformat like 2005-April-19.

<cfset find_date = #DateFormat(find_date, "yyyy-mmmm-d")#>
<cfoutput>#find_date#</cfoutput>

it shows up as 2038-January-14

How can I convert it correctly ?

Thanks,
olmos
 
Well...did some tests... this is what I got to work:

Code:
  <cfset find_date = "050419"> 
  <cfset find_date =   insert("/","#find_date#",4)>
  <cfset find_date =   "20"&insert("/","#find_date#",2)>
  <cfset find_date = #DateFormat(find_date, "yyyy-mmmm-d")#>
  <cfoutput>#find_date#</cfoutput>

I found that I had to add the "20" on the second insert otherwise the system returned 2019-May-4 instead of the desired 2005-April-19.

Hope it helps.
 
yes, that string is not recognized by CF as a date- so a dateFormat won't work. You have use that value to create a date value, then apply formatting.

<cfset find_date = '050419'>
<cfset real_date = CreateDate(Left(find_date,2),Mid(find_date,3,2),Right(find_date,2))>
<cfset formatted_date = DateFormat(real_date,'yyyy-mmmm-d')>
<cfoutput>#formatted_date#</cfoutput>


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
Thank you for all your help, it is now working.

olmos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top