DateFormat / Timestamp

I know this should be easy but I can't seem to find out the following. If I'm using a JavaScript calendar and the formatting is yyyy/mm/dd when a date is selected. How can input the the yyyy/mm/dd formated text to a timestamp so I can format the date however I need to in the future.  For example : {ts '2007-07-26'} format.


Who is Participating?
Since the format of your date is not coldfusion's standard format, it may not correctly understand the date.  For example is 2007/12/1  Dec 1st or Jan 12th?

You can test this to see if CF gets it right, or you can parse it out manually and create the date like this...

<cfset theDate = createDate( listFirst(theString,"/"), listGetAt(theString,2,"/"), listLast(theString,"/") )>

 Now the variable theDate will contain a valid date and you can format it using
  dateFormat(theDate, "mm/dd/yyyy")
or insert it into the database using..

If there is a chance this parsing will not contain a valid date, enclose the statement in CFTRY and CFCATCH statements to ensure your createDate() does not throw an error.

Scott BennettManager TechnologyCommented:
just use parsedatetime:

Scott BennettManager TechnologyCommented:
That is not neccessary. yyyy/mm/dd is indeed how coldfusion expects it for the parsedateeimt function. You would only have to do the createDate method if you were using yyyy/dd/mm and then it would be :
<cfset theDate = createDate( listFirst(theString,"/"), listLast(theString,"/"), listGetAt(theString,2,"/") )>

try it out:
<cfset mydate="2007/12/1">
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.