PDA

View Full Version : DateDiff (Foxpro - oh no!)


georgev
05-10-07, 05:56
Hey all,

wondering if you can help me, I can't seem to find a function for calculating the difference between two dates in days.

Any suggestions? I thought there'd be an inbuilt function for this, but so far I've had no luck in finding it!

-GeorgeV

georgev
05-10-07, 06:19
Ok, here's my reasonable effort/solution

myString = "10/05/2007"
myString2 = "25/05/2007"

MyDate = CTod(MyString)
MyDate2 = CTod(MyString2)

x = 0
If MyDate < MyDate2
Do While MyDate + x <> MyDate2
x = x + 1
EndDo
Else
Do While MyDate + x <> MyDate2
x = x - 1
EndDo
EndIf

? x

I'm not exactly happy with it, but it'll have do for now.

Any more ideas are more than welcomed :)

georgev
05-10-07, 07:54
And after all that, look what I stumble over:

DayDif(<First Date>, <Second Date>)

Similar functions available for month, week & year.
*sigh*

RedAxl
05-30-07, 03:27
Hi Gorge

In Foxpro, you can simply subtract the two dates directly
and it will return the difference in days.
Just store the return value in integer type variable.

Ex.
vdate1 = {6/30/2007}
vdate2 = {7/10/2007}

vdays = vdate2 - vdate1

Goodluck!
Red