DateFormat() in the twilight zone

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zigman68
    New Member
    • Feb 2008
    • 1

    DateFormat() in the twilight zone

    I have a problem with the DateFormat() Function that is driving me nuts!
    I am downloading a csv and then parsing through it, then inserting into a SQL 2005 DB. Here is the problem. ...
    A number of fields that are passed are strings representing dates.
    E.G. 20080324
    ( which I read as 2008/03/24)
    Sometimes they are there sometimes they are not.
    When I perform a DateFormat on them to set them in my VAR, this is what I am getting back for the same data:
    01/20/56878

    Now I may be missing something but those are not even the same numbers.



    Here is a sample of my code:


    [CODE=cfm]<CFIF FileExists("#cs vTSSavePath#\#c vsTSFilename#.C SV")>
    <cffile action="read" file="#csvTSSav ePath#\#cvsTSFi lename#.CSV" variable="csvFi le">
    <cfset csvFile = Replace(csvFile , chr(34), "", "all")>
    <!--- Convert the lines to an array using the carriage return/line feed characters as delimiters --->
    <cfset FileLines = listtoarray(Lis tFix(csvFile)," #chr(13)##chr(1 0)#")>
    <!--- Loop through the array of lines Use the number from="2" to eliminate the first row of data--->
    <cfloop from="2" to="#arrayLen(F ileLines)#" index="i">
    <cfset AUCTDATE = "#listgetat(Fil eLines[i],11)#">
    <cfset DEFLTDAT = "#listgetat(Fil eLines[i],10)#">
    <cfset PUBDATE = "#listgetat(Fil eLines[i],126)#">
    <cfset RECDATE = "#listgetat(Fil eLines[i],125)#">
    <cfset LOAN_DATE = "#listgetat(Fil eLines[i],3)#">
    <cfset DATE_SOLD = "#listgetat(Fil eLines[i],72)#">
    <CFIF AUCTDATE EQ "NULL"><cfs et AUCTDATE = "NULL"><CFELSE> <cfset AUCTDATE = "#DateFormat(li stgetat(FileLin es[i],11), "mm/dd/yyyy")#"></CFIF>
    <CFIF DEFLTDAT EQ "NULL"><cfs et DEFLTDAT = "NULL"><CFELSE> <cfset DEFLTDAT = "#DateFormat(li stgetat(FileLin es[i],10), "mm/dd/yyyy")#"></CFIF>
    <!--- <CFIF PUBDATE EQ "NULL"><cfs et PUBDATE = "NULL"><CFELSE> <cfset PUBDATE = "#DateFormat(li stgetat(FileLin es[i],126), "mm/dd/yyyy")#"></CFIF> --->
    <CFIF RECDATE EQ "NULL"><cfs et RECDATE = "NULL"><CFELSE> <cfset RECDATE = "#DateFormat(li stgetat(FileLin es[i],125), "mm/dd/yyyy")#"></CFIF>
    <CFIF LOAN_DATE EQ "NULL"><cfs et LOAN_DATE = "NULL"><CFELSE> <cfset LOAN_DATE = "#DateFormat(li stgetat(FileLin es[i],3), "mm/dd/yyyy")#"></CFIF>
    <CFIF DATE_SOLD EQ "NULL"><cfs et DATE_SOLD = "NULL"><CFELSE> <cfset DATE_SOLD = "#DateFormat(li stgetat(FileLin es[i],72), "mm/dd/yyyy")#"></CFIF>


    <cfoutput>
    #AUCTDATE#<BR />
    #DEFLTDAT#<BR />
    #PUBDATE#<BR />
    #AUCTDATE#<BR />
    #RECDATE#<BR />
    #LOAN_DATE#<BR />
    #DATE_SOLD#<BR />
    </cfoutput>[/CODE]



    Any help would be much apreciated. Thanks in advance.
    Last edited by acoder; Mar 11 '08, 01:37 PM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN!

    The date is a string, not a date/time object which is what DateFormat expects for the first parameter. If you're passing it as a string, it must be within quotes, or you can use CreateDate() to create a date/time object.

    Comment

    Working...