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

dBase III - indexing on date 2

Status
Not open for further replies.

turvillevalley

Programmer
Apr 18, 2005
3
GB
My dBase Bible tells me that if I index on date (MM/DD/YY)I'll end up with a list sorted by Month, first.
It then says I should ...
index on $(Date,7,2)
... which translates as "Index on the last two characters in the date starting with the 7th character"

The trouble is I get told this is a syntax error!
I have tried all the permutations I can think of to no avail - does anybody have any Idea how I can acheive a 'proper' Date Index, please?

Regards,

Chris
 
To the best of my knowledge, you'll have to turn your date into a character string to do this. Try indexing on DTOC(<your date>) and you should be alright.

There's always a better way. The fun is trying to find it!
 
Thanks TVIMAN,

Being impatient I actually ended up using DTOC as a work around, a pretty tedious one, but it seems to have worked.
That said, it's nice to know that my train of thought was on a similar track to somebody else.

Thanks for your help.

Best regards,

Chris
 
Wow, dBase 3 goes way back in time. Does it have the DTOS() function? It will return the date as an 8-character string such as "20050425", the perfect arrangement for most indexes.

If using DTOC() then this longer code does the same, assuming your display format is mm/dd/ccyy:

* myDate is a date field
SET CENTURY ON
INDEX ON RIGHT(DTOC(myDate),4)+LEFT(DTOC(myDate),2)+SUBSTR(DTOC(myDate),4,2) TAG DateOrder

Just remember not to reindex and accidently change the index logic by having CENTURY set off when it should be on, or the index will display a skewed order! Of course if you keep the century off all the time, then this will work:

INDEX ON RIGHT(DTOC(myDate),4)+LEFT(DTOC(myDate),2)+SUBSTR(DTOC(myDate),4,2) TAG DateOrder

dbMark
 
Thanks dbMark - Your are correct, db III goes Way back, 1985, at least!

Unfortunately there's no Century to set!
Also it only has DTOC, not DTOS.
So, it looks like the work-around which TVIMAN suggested is the best bet. In fact, the work around works well, luckily for me.


All the best,

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top