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

Sorting Dates

Status
Not open for further replies.

Dazb75

Programmer
Aug 14, 2002
10
GB
Hi there folks ...

I'm trying to compare three dates on a form (if they exist!) and then return the most recent date. I've tried adding the 3 values to an array and sorting it, but I don't think that Asort() works on dates!

I'm sure that there's should be some way of doing it with a couple of if ... else ... statements, but I can't figure out how to skip the dates that don't exist.

Any ideas?
 
If date1 > date2 and date1 > date3
return date1
else
if date2 > date3
return date2
else
return date3
endif

this should do it...

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Oh, for the date that don't exist. YOu can use

If empty(cdDate)
messagebox("You have an empty date")
endif

if the dates are characters, make sure you use ctod() to convert to date value.

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
I've tried adding the 3 values to an array and sorting it, but I don't think that Asort() works on dates!


Maybe so. But if you store the DTOS() of the dates, they'll sort just the way you want them.

But a much easier way is to use the MAX() function.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top