Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code to find all invalid dates
Message
From
28/06/2013 13:40:09
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 8
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01577415
Message ID:
01577417
Views:
78
>How do write a code that goes through all my database table looking for invalid dates residing
>in the tables? I need it to list the table name, field name and the invalid date.

What constitutes an invalid date? If VFP throws an error using it, then:
lnTables = ADBOBJECTS(laTables, "TABLE")
FOR lnI = 1 TO lnTables
    USE (laTables[lnI]) ALIAS myTable

    * For a specific date, use TYPE().
    * To find all date fields, put an inner loop below to go FOR lnJ = 1 to FCOUNT() and use FIELD() to get each name and type, and test each date found
    IF TYPE("myTable.dDateField") = "D"
        SCAN
            TRY
                lcDateTest = DTOC(myTable.dDateField)
        
                * OR:
                *REPLACE dDateField WITH dDateField IN myTable
        
            CATCH
                ? "Bad date on RECNO(): " + TRANSFORM(RECNO())
            ENDTRY
        ENDSCAN
    ENDIF
    USE in myTable
NEXT
If a bad date is outside of a valid range for the accounting year, etc., then you would use logic.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform