DateFormat / Timestamp

Posted on 2007-07-26
Last Modified: 2013-12-16
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.


Question by:brihol44
    LVL 14

    Expert Comment

    just use parsedatetime:

    LVL 39

    Accepted Solution

    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.

    LVL 14

    Expert Comment

    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">

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Building “do-it-yourself” web sites has become an epidemic. There are so many blogs, web sites and even books that "teach" you how to build your web site in a few extremely simple and easy steps. Building a web site has become easier than boiling an…
    This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
    The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
    The viewer will learn how to count occurrences of each item in an array.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now