Converting a File Date to a recognised ColdFusion format

Posted on 2006-03-22
Last Modified: 2013-12-24
I need to be able to allow a user to enter a date into a form, and on processing the form I need to open a file which has a last modified date which is the same as "form.MyDate".  I have tried using CFDirectory and reading Name.DateLastModified, but I get the following error:

The value "Wednesday, 4 January 2006 12:42:48 PM NZDT" could not be converted to a date.  Is there an easy way of converting that value into a dd/mm/yyyy value?


Question by:jdthedj
    LVL 16

    Accepted Solution

    Can you provide your actual search format...
    I've done this without a problem... (on mx6.1 and 7 in a Windows box...)

    <CFSET mydirectory = getDirectoryFromPath(getCurrentTemplatePath())>
    <CFSET yesterday = dateadd('h',-24,now())>
    <table border>
    <th>Name<th>Size<th>Type<th>Date Last Modified<th>Age

    <cffunction name="walkDir" access="Private" output="Yes">
     <cfargument name="DirPath" type="string" required="Yes">
     <cfdirectory action="list" directory="#DirPath#"
                 name="filelist" sort="DateLastModified DESC">
    <CFOUTPUT query="filelist">
    <CFIF yesterday LTE datelastmodified>NEW<cfelse>OLD</cfif>
    <CFIF filelist.type EQ "Dir">#walkDir(DirPath & & "\")#</CFIF>
    LVL 3

    Author Comment

    Thanks for the reply RCorfman

    Here is my code (CF 6.1)

    <CFSET MyDate = CreateODBCDate(form.WEnded)>

    <CFDIRECTORY DIRECTORY="#Session.MTSDir#\#form.Branch#" NAME="GetMTS">


    <CFIF DateAdd("d",-2,#GetMTS.DateLastModified#) EQ #MyDate#>


    etc etc

    Your code works, but I cannot see why mine doesn't.  What am I doing wrong?

    LVL 16

    Expert Comment

    I must have had a lapse in my email. I didn't see your post on 3/23. I assume you got it figured out. Sorry for not helping further.  I suspect the problem was the EQ #MyDate# instead of a range... like GTE LTE, or both with two dates to check a range...
    LVL 3

    Author Comment

    I cheated in the end and parsed the long date as shown in my question.  I think you are correct about the EQ because I still had trouble within the query from the directory and i had to use more than one cfif to get it sorted.

    Thanks for your help.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Article by: kevp75
    Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Open Page or Post…
    The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now