Re: Fastest way to convert 1000's of YYYYMMDD char dates to real dates?



*test 1
s= SECONDS()
x = "20070812"
FOR i=1 TO 5000
d=eval("{^"+tran(x,"@R 9999/99/99")+"}")
NEXT
? SECONDS()-s

*test 2
s=SECONDS()
x = "20070812"
FOR i=1 TO 5000
d=DATE(VAL(LEFT(x,4)),VAL(SUBSTR(x,3,2)),VAL(RIGHT(x,2)))
NEXT

Test 2 appears to be at least 25% faster.
-Anders

"Lew" <lew@xxxxxxxxxxx> wrote in message
news:eC0T7xUNIHA.4880@xxxxxxxxxxxxxxxxxxxxxxx
Giancarlo's eval() solution is unexpectedly quick, although, given the
fact that dates are stored in tables in YYYYMMDD format, you'd think
there'd be a strictdate 0 builtin. Your append from text takes advantage
of that.

"Anders Altberg" <anders.altberg> wrote in message
news:%23$QzksUNIHA.2000@xxxxxxxxxxxxxxxxxxxxxxx
If they are in in a column, put them into a textfile:
SELECT table
COPY TO dates.txt FIELDS id, date DELIMITED
then:
CREATE CURSOR Dates (id int , d1 date)
SET DATE YMD
APPEND FROM dates.txt DELIMITED

or, using some VFP functions:
x = "20070812"
? DATE(VAL(LEFT(x,4)),VAL(SUBSTR(x,3,2)),VAL(RIGHT(x,2)))

-Anders

"Giancarlo Piccinato" <piccinato@xxxxxxxxxxx> wrote in message
news:u79etzTNIHA.5988@xxxxxxxxxxxxxxxxxxxxxxx
Try this:

eval("{^"+tran("20071202","@R 9999/99/99")+"}")

Giancarlo

"Lew" <lew@xxxxxxxxxxx> wrote in message
news:Oefm0WTNIHA.2308@xxxxxxxxxxxxxxxxxxxxxxx


--
-Lew
The workers took the robot for Maria.






.



Relevant Pages

  • Re: Fastest way to convert 1000s of YYYYMMDD char dates to real dates?
    ... CREATE CURSOR Dates (id int, ... SET DATE YMD ... APPEND FROM dates.txt DELIMITED ... or, using some VFP functions: ...
    (microsoft.public.fox.programmer.exchange)
  • Re: DTS ActiveX Scripting
    ... Now, you would like to append "Hello,again" string as a new row ... DECLARE @FS int, @OLEResult int, @FileID int ... EXEC spAppendToFile 'D:\Append.txt','Hello,again' ...
    (microsoft.public.sqlserver.programming)
  • Re: How can I use sendmessage to input some text into Richtextbox(C#)?
    ... But what I want to do is to append. ... private static extern int SendMessage(IntPtr hWnd, int wMsg, int ... private const int EM_REPLACESEL = 0xC2; ... you only want to send key down messages to controls if you want ...
    (microsoft.public.dotnet.framework)
  • Re: An array within a table--Break into 1-to-1 mini tables or separate rows?
    ... If you don't mind a vertical view, append the six records with the ... Any hints on how to easily display all six Yes/No records on 1 form as ... The reason I kept leaning towards putting the six grade fields into 1 ... Grade_CommunicationRating Int ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Add items to an array
    ... but I cannot figure out how to append these numbers ... The array serials[] is one containing ints. ... You certainly haven't created an int of any ... Why not an array of strings? ...
    (comp.lang.c)