See Also Cvt YYYYDDD 2 Date10/23/2002 - Steven Blake The reverse operation to the DTOS() function has always seemed a curious omission in the supplied arsenal from Microsoft, especially before the introduction of the Strict Date Format. Of course, it's easy enough to remedy with a UDF (User Defined Function) to validate and to convert the CCYYMMDD data string occurring mostly in download files.
Although SQL - Date Types, both datetime and smalldatetime, can accept the DTOS() format as input, there is a limited range to the dates that are valid. My long time (DOS days) function STOD() had to be modified to test input for Microsoft® SQL Server™ front end applications. The current version of STOD() now also enforces those date limits within FoxPro but that has not presented a problem (yet).
Empty dates, available as blanks in FoxPro, convert to January 1, 1900 in SQL Server which is not only a valid date but also usually within the range of user input. So I can force NULL results in STOD() when there is an empty date.
The additional case statements evaluating the date parts are the result of a one-time bug in either FoxPro or dBase (or both.) A leap year date could be returned for any year at end of a century (i.e., 1800, 1900) when it did not actually occur, so I took over the audit to prevent those incorrect extra days.