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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Info On How To Use Date As Part Of An Index PART 2

Status
Not open for further replies.

drosenkranz

Programmer
Sep 13, 2000
360
US
I know you can use dtoc() or dtos() but I didn't think that would work for creating a chronological index. For instance:

Using this, wouldn't November and December dates appear after January dates- Then February, March April, etc? 3/12/00 does come after 12/1/00 in an Ascii sort.

Wouldn't all of the dates' years be subject to the same thing. 00 would come before 99, etc?

I thought you'd have to do something "like" this:

Alltrim(Upper(Case_No) +Year(date_comp) + Month(date_comp) + Day(date_comp)

The problem is that this tries to concateneate strings and numbers- and just like strings and dates- FoxPro won't buy it. If I converted these date functions to strings, I'd lose the leading zeroes anyway.

Can anybody answer this or am I missing something here on how VFP is evaluating the dtoc() and dtos() date conversion expressions used in an index?
 
dtoc function have special option for indexes. For example,

INDEX ON dtoc(dDateField,1)

This will give you exactly the same index order as you want.

Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
00 would come before 99, etc?

DTOS() and DTOC(,1) return an eight character string in the format of YYYYMMDD.

Therefore 1999 would come before 2000.

Refer to the VFP help file for more info on these functions.

Straight from the VFP docs:
This function is useful for indexing tables on a Date or DateTime field. It is equivalent to DTOC( ) when its optional 1 argument is included.

The character string returned by DTOS( ) isn't affected by SET DATE or SET CENTURY.
Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top