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

subtract num of days between two dates

Status
Not open for further replies.

kenndot

Programmer
May 15, 2001
316
US
Is there a function similar to datediff in Foxpro? I've seen some functions that calculate the weeks and return the day of the month from the string, but none that actually will give the difference between two dates. The month or year will not always be the same either.

Any ideas?

Thanks
 
I'll bet if you just put the minus sign between 2 dates you will notice FoxPro will return the difference in Days.
lnDays = ldDate1 - ldDate2 David W. Grewe
Dave@internationalbid.com
 
Actually, no. I've tried that several times and I get the Data Type Mismatch error.

What I'm actually trying to do is this. In the code, I'm pulling out two dates from another table and putting those into their own fields in a cursor and from there trying to subtract how many days between the two dates. Here's the code I have.

SELECT Closedate, Req_Recd, Req_Recd - Closedate / 86400 as TimeToClose ;
FROM Phonelog ;
WHERE Phonelog.ProdLine !="Commercial" ;
INTO CURSOR csrCompLen

I assumed I could just do the math in the cursor, but it isn't getting past the calculation. I've gotten Data type mismatch and also the wrong operand error as well. I've enclosed them in Parens too. Any ideas?

 
Closedate / 86400 as TimeToClose
You are dividing a date field with a integer?
There is your data type mismatch David W. Grewe
Dave@internationalbid.com
 
Just in case anyone is interested... here was the problem...

One of the fields was DateTime and the other Date, it didn't like that. I thought I had read in MSDN that it didn't matter, but it apparently does.

And then, VOILA! I got the number of days just by subtracting. Thanks for making me think!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top