Skip to main content
nikos101
Inspiring
June 30, 2010
Answered

I need to loop through <cfdirectory

  • June 30, 2010
  • 1 reply
  • 3050 views

I need to loop through this query and add a new column to each row in fileQuery query which contains the a date object represented in the filename

<cfdirectory directory = "#dir#" name = "fileQuery" sort = "datelastmodified">

the fileQuery.fileName is of the following format

staffID1247date12_30_2000.flv

(note the date is MM DD YYYY)

Could anyone advise?

Message was edited by: nikos101

    This topic has been closed for replies.
    Correct answer ilssac

    hmm

    Fri Jul 2 00:00:00 GMT+0100 2010   
    is been turned into 2000_07_02

    by

    DateFormat(FORM.date, 'yyyy_mm_dd')

    so sad


    That's because dateFormat() expects a date object

    Fri Jul 2 00:00:00 GMT+0100 2010 is a date string

    ColdFusion functions can sometimes figure out a date string and automagically make a date object out of one when it needs to.  But it is far from fool proof.

    It is a better pratcice not to rely on this and use the parseDate() or the more explict createDate() when necessary.

    1 reply

    Inspiring
    June 30, 2010

    You can use string and list functions to extract the string and parsedatetime to convert the string to a date. 

    nikos101
    nikos101Author
    Inspiring
    June 30, 2010

    Ok, but how would I parse out the date using regex?


    Inspiring
    June 30, 2010

    Which part of creating the regex are you having trouble with?

    My approach would be to match the entire string, making sure to capture subexpressions for the dd, mm & yyyy parts.  Then replace the whole thing with \3-\2-\1 (where those are yyyy, mm, dd).  That will leave you with an unambiguous string which you can pass into parseDateTime() to create your date object.

    --

    Adam