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!

Will FoxPro do date and time calculations?

Status
Not open for further replies.

JKJohnston

Programmer
Apr 6, 2001
3
CA
I'm trying to determine the number of hours between two date and time fields. The fields are stored in text format each in a separate field. I concantenate them together but when I use the CTOD() function I get nothing returned (to be precise I get / / returned). Is FoxPro not capable of date/time calculations?

Thanks,
 
Hi
** difference in days .. nDays is calculated as
nDays = CTOD(fldToDate)-CTOD(fldFromDate)

Unfortunately, there is no function built in foxpro ver 2.6 for the time calculation. However you can do a calculation.. by striping the time field..

You can use SUBSTR() function to strip the TIme field to
chrs, cMinutes and cSeconds. Convert it to numeric using VAL(cHrs) etc and get numerical figures.. nHrs, nMinutes and nSeconds.
Then
startTime = (nHrs*60*60)+(nMinutes*60)+(nSeconds)
EndTime = (nDays*24*60*60)+(nHrs*60*60)+(nMinutes*60)+(nSeconds)
Difference = EndTIme-StartTIme && in seconds
Convert back to days, hrs, minutes and seconds.

If you are starting a new application.. think of using VFP where you have a dateTime variable and difference gives the
seconds between them. That is so easy.

Hope this helps you :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
When you said the dates are stored as Character fields.
Please state how they are stored.
20020131 for 01/31/2002 or
020131 for 01/31/2002 or
013102 for 01/31/2002 0r
310102 for 01/31/2002 0r
01/31/02 etc

As Ramani stated FoxProWin 2.x can not subtract time but VFP can. But if you can not upgrade to VFP and it must be done in FPW. Look for the 4 routines that begin with "TM_" in this file listed below. Cut, paste, alter, discard as you see fit.
David W. Grewe
Dave@internationalbid.com
 
Thanks for the help. I can't upgrade to VFP (would be nice but money is always an issue and our IS department doesn't support it at all).

I've tried your solution, ramani, and it seems to solve the problem. I'll give your code a closer look, Dave, later today.

Again thanks for the help.

J
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top