Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Conversion Code Problem

Status
Not open for further replies.

klc

Programmer
Nov 7, 2000
5
US
The following is FoxProWin 2.6a code that I'm trying to use to reset a date field which is parsed into a table "Results1" from a vendor prioritary analyzer (which is not Y2K compliant and too expensive to update). I have been simply using:

REPLACE daterun1 with {01/01/2002} for daterun1={01/01/1902}
REPLACE daterun1 with {01/02/2002} for daterun1={01/02/1902}
etc, etc.

I am tired of this process and am trying to code a change, but the following code only replaces the field daterun1 with 00/00/00. I'm assuming it is using the value from the initial memvar setup from mdaterun1={}. What am I doing wrong? Thanks for your help!


* DateConv.prg DateConversion
* To reset the date/year 1900 to 2000 or 1901 to 2001 etc.
* Keeps day and month and only changes year.
* Table is "Results1.dbf" and field to change is Daterun1
*
SET CENTURY ON

USE Results1

mdaterun1={}
daterun1 = mdaterun1

DO WHILE NOT EOF()
IF (NOT EMPTY(daterun1)) and (daterun1 < CTOD(&quot;01/01/1940&quot;)) ;
mdaterun1 = CTOD(LTRIM(STR(MONTH(daterun1))) + &quot;/&quot; + ;
LTRIM(STR(DAY(daterun1))) + &quot;/&quot; + ;
LTRIM(STR(YEAR(daterun1) - 1902 + 2002 )))
ENDIF

REPLACE Results1.daterun1 with mdaterun1

SKIP
ENDDO
*EndOfCode
 
I see two things that can give you problems.
1) The &quot;;&quot; on the end of your IF line. i.e.
IF (NOT EMPTY(daterun1)) and (daterun1<CTOD(&quot;01/01/1940&quot;)) ;

2) Since the REPLACE isn't conditional, any records that didn't evaluate .T. will be updated with the value of mdaterun1 that was set from the last .T. record. Perhaps the REPLACE needs to be inside the IF statements range.

Also, I'm not sure what good the &quot;daterun1 = mdaterun1&quot; statement is. It just creates a memory variable (m.daterun1) that's never used.

Rick
 
To skip century, is good function
GOMONTH(PastDate,1200) ... search Y2k !
 
Or why not this?:

SET CENTURY ON

USE Results1
REPLACE daterun1 WITH CTOD( padl(alltrim(STR(MONTH(daterun1))),2,&quot;0&quot;) + &quot;/&quot; + padl(alltrim(STR(DAY(daterun1))),2,&quot;0&quot;) + &quot;/20&quot; + right(alltrim(STR(YEAR(daterun1))),2) ) FOR (NOT EMPTY(daterun1)) and (daterun1 < CTOD (&quot;01/01/1940&quot;))
 
How about :

REPLACE ALL DateRun1 WITH GOMONTH(DateRun1, 1200) FOR DateRun1 < {01/01/1940}

Incidentally, :

DO WHILE NOT EOF()
...
SKIP
ENDDO

is better written as :

SCAN
...
ENDSCAN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top