PRB: DTOC() Returns Unexpected Results When Used with Dates

ID: Q99618


The information in this article applies to:


SYMPTOMS

When comparing date fields and character strings so that the results of the comparison reflect a given range of dates, the comparison must be done by using the CTOD(<string>) command, rather than using the DTOC(<date field>) command.


MORE INFORMATION

Consider the following code:


date_fld=03/01/93  && An actual date field.
comp_str="04/01/90"  && The string to compare.

BROWSE FOR DTOC(date_fld)>comp_str 
The BROWSE command above does not return 03/01/93 as being greater than 04/01/90 because the strings are compared from left to right and the month takes precedence in a straight string comparison regardless of the year. To obtain the correct result, the strings must be compared as date to date rather than string to string. To perform this type of comparison, modify the BROWSE command to read as follows:

BROWSE FOR date_fld>CTOD(comp_str) 
This type of BROWSE command ensures the year is compared before the month, and therefore the desired results are returned.

Additional query words:


Keywords          : kbGrpFox FoxDos FoxWin FxprgBrowse 
Version           : MACINTOSH:2.01; MS-DOS:2.0,2.1,2.5,2.5a; WINDOWS:2.5,2.5a
Platform          : MACINTOSH MS-DOS WINDOWS 
Issue type        : kbprb 

Last Reviewed: April 19, 1999