• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

Converting a File Date to a recognised ColdFusion format

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?

TIA

John
0
jdthedj
Asked:
jdthedj
  • 2
  • 2
1 Solution
 
RCorfmanCommented:
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())>
Yesterday=<cfoutput>#yesterday#</cfoutput>
<table border>
<th>Name<th>Size<th>Type<th>Date Last Modified<th>Age
<cfoutput>#WalkDir(myDirectory)#</cfoutput>
</table>

<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">
<tr><td>#DirPath##name#<td>#size#<td>#type#<td>#datelastmodified#<td>
<CFIF yesterday LTE datelastmodified>NEW<cfelse>OLD</cfif>
<CFIF filelist.type EQ "Dir">#walkDir(DirPath & filelist.name & "\")#</CFIF>
</cfoutput>
</cffunction>
0
 
jdthedjAuthor Commented:
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">

<CFOUTPUT QUERY="GetMTS">

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

<CFFILE ACTION="Read"
    FILE="#Session.MTSDir#\#form.Branch#\#GetMTS.Name#"
    VARIABLE=MyFile>

etc etc

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

0
 
RCorfmanCommented:
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...
0
 
jdthedjAuthor Commented:
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.

John
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now