Connecting Tech Pros Worldwide Help | Site Map

DateFormat() in the twilight zone

zigman68's Avatar
Newbie
 
Join Date: Feb 2008
Posts: 1
#1: Mar 11 '08
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:


Expand|Select|Wrap|Line Numbers
  1. <CFIF FileExists("#csvTSSavePath#\#cvsTSFilename#.CSV")>
  2. <cffile action="read" file="#csvTSSavePath#\#cvsTSFilename#.CSV" variable="csvFile">
  3. <cfset csvFile = Replace(csvFile, chr(34), "", "all")>
  4. <!--- Convert the lines to an array using the carriage return/line feed characters as delimiters --->
  5.     <cfset FileLines = listtoarray(ListFix(csvFile),"#chr(13)##chr(10)#")>
  6. <!--- Loop through the array of lines Use the number from="2" to eliminate the first row of data--->
  7.         <cfloop from="2" to="#arrayLen(FileLines)#" index="i">
  8.             <cfset AUCTDATE = "#listgetat(FileLines[i],11)#">
  9.             <cfset DEFLTDAT = "#listgetat(FileLines[i],10)#">
  10.             <cfset PUBDATE = "#listgetat(FileLines[i],126)#">
  11.             <cfset RECDATE = "#listgetat(FileLines[i],125)#">
  12.             <cfset LOAN_DATE = "#listgetat(FileLines[i],3)#">
  13.             <cfset DATE_SOLD = "#listgetat(FileLines[i],72)#">
  14.             <CFIF AUCTDATE EQ "NULL"><cfset AUCTDATE = "NULL"><CFELSE><cfset AUCTDATE = "#DateFormat(listgetat(FileLines[i],11), "mm/dd/yyyy")#"></CFIF>
  15.             <CFIF DEFLTDAT EQ "NULL"><cfset DEFLTDAT = "NULL"><CFELSE><cfset DEFLTDAT = "#DateFormat(listgetat(FileLines[i],10), "mm/dd/yyyy")#"></CFIF>
  16.             <!--- <CFIF PUBDATE EQ "NULL"><cfset PUBDATE = "NULL"><CFELSE><cfset PUBDATE = "#DateFormat(listgetat(FileLines[i],126), "mm/dd/yyyy")#"></CFIF> --->
  17.             <CFIF RECDATE EQ "NULL"><cfset RECDATE = "NULL"><CFELSE><cfset RECDATE = "#DateFormat(listgetat(FileLines[i],125), "mm/dd/yyyy")#"></CFIF>
  18.             <CFIF LOAN_DATE EQ "NULL"><cfset LOAN_DATE = "NULL"><CFELSE><cfset LOAN_DATE = "#DateFormat(listgetat(FileLines[i],3), "mm/dd/yyyy")#"></CFIF>
  19.             <CFIF DATE_SOLD EQ "NULL"><cfset DATE_SOLD = "NULL"><CFELSE><cfset DATE_SOLD = "#DateFormat(listgetat(FileLines[i],72), "mm/dd/yyyy")#"></CFIF>
  20.  
  21.  
  22.             <cfoutput>
  23.                 #AUCTDATE#<BR />
  24.                 #DEFLTDAT#<BR />
  25.                 #PUBDATE#<BR />
  26.                 #AUCTDATE#<BR />
  27.                 #RECDATE#<BR />
  28.                 #LOAN_DATE#<BR />
  29.                 #DATE_SOLD#<BR />
  30.             </cfoutput>


Any help would be much apreciated. Thanks in advance.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Mar 11 '08

re: DateFormat() in the twilight zone


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.
Reply