How to Index a Combined Date and Character Field

ID: Q97066


The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxBASE+ for Macintosh, version 2.01
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5
  • Microsoft FoxPro for Windows, versions 2.0, 2.5
  • Microsoft FoxPro for Macintosh, version 2.5


SUMMARY

To create an index on combined Date and Character type fields, you must break the Date type field into separate year, month, and day components; use the STR() function to connect the date pieces in the correct order; and then add the Character type field to the date string.

You can use the following examples to create an index on combined Date and Character type fields (the INVOICES database is referenced in the examples):

INDEX ON STR(YEAR(idate))+STR(MONTH(idate))+STR(DAY(idate))+cno TO "date_cno.idx"

-or-

INDEX ON DTOC(idate, 1)+cno TO "date_cno.idx"

-or-

INDEX ON DTOS(idate)+cno TO "date_cno.idx"
NOTE: The third example above applies ONLY to FoxPro versions 2.0 and later (including FoxPro for Macintosh), not to FoxBASE+.


REFERENCES

"Microsoft FoxBASE+ Commands & Functions," page 4-22
"Microsoft FoxPro Language Reference," version 2.5, page L3-473

Additional query words: VFoxWin FoxWin FoxDos FoxMac 2.01 index cross- platform

Keywords : FxprgGeneral
Version : MACINTOSH:2.01,2.5; MS-DOS:2.0,2.5; WINDOWS:2.0,2.5,3.0
Platform : MACINTOSH MS-DOS WINDOWS
Issue type :


Last Reviewed: February 2, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.