Date Difference function 
Author Message
 Date Difference function

Before I write my own, I thought I'd ask to see if anybody had or knew
of a VFP5.0 function that will perform a date comparison.  Particularly
as follows:

DateComp(startDate, endDate)

and will return the number of MONTHS between the two dates.  I was
unable to find such a function within VFP as it is.

Please post reply or send directly to

Thanks in advance,

Derek Smith



Sun, 02 Jul 2000 03:00:00 GMT  
 Date Difference function

Derek,

Would this do?

   LPARAMETERS d1, d2
   IF EMPTY(d1) OR EMPTY(d2)
     RETURN
  ENDIF
  LOCAL minDate, MaxDate, MonthsBetween
    mindate=MIN(d1,d2)
    maxdate = MAX(d1,d2)
    monthsbetween = (YEAR(maxdate) - YEAR(mindate)) * 12 + ;
       ( MONTH(maxdate) - MONTH(mindate) )

You may want to do an adjustment for less than whole months.
IF DAY(maxdate) < DAY(mindate)
   monthsbetween = monthsbetween - 1
ENDIF

-Anders

Quote:

>Before I write my own, I thought I'd ask to see if anybody had or knew
>of a VFP5.0 function that will perform a date comparison.  Particularly
>as follows:

>DateComp(startDate, endDate)

>and will return the number of MONTHS between the two dates.  I was
>unable to find such a function within VFP as it is.

>Please post reply or send directly to

>Thanks in advance,

>Derek Smith



Sun, 02 Jul 2000 03:00:00 GMT  
 Date Difference function


Quote:
> I thought I'd ask to see if anybody had or knew
> of a VFP5.0 function that will perform a date comparison.  Particularly
> as follows:

> DateComp(startDate, endDate)

> and will return the number of MONTHS between the two dates.  I was
> unable to find such a function within VFP as it is.

I don't know of one, either, but it would be a useful function to have,
rather than just being able to do days...

? DateDiff(dStart, dEnd, 'Week')
--
Garrett Fitzgerald
Programmer/Analyst
UNICOM
Providence, RI
#INCLUDE "\Program Files\DevStudio\VFP\StdDsclm.h"



Mon, 03 Jul 2000 03:00:00 GMT  
 Date Difference function

Quote:

> > I thought I'd ask to see if anybody had or knew
> > of a VFP5.0 function that will perform a date comparison.  Particularly
> > as follows:

> > DateComp(startDate, endDate)

> > and will return the number of MONTHS between the two dates.  I was
> > unable to find such a function within VFP as it is.


> I don't know of one, either, but it would be a useful function to have,
> rather than just being able to do days...

Have you checked GOMONTH()?

Jack



Mon, 03 Jul 2000 03:00:00 GMT  
 Date Difference function


Quote:

> > > I thought I'd ask to see if anybody had or knew
> > > of a VFP5.0 function that will perform a date comparison.  

> > I don't know of one, either, but it would be a useful function to have,
> > rather than just being able to do days...
> Have you checked GOMONTH()?

Yes, but I was thinking more of a function that could handle anything,
from second to year resolution. I could write it, of course, but it's
more fun to see it installed as part of the language... :-)
--
Garrett Fitzgerald
Programmer/Analyst
UNICOM
Providence, RI
#INCLUDE "\Program Files\DevStudio\VFP\StdDsclm.h"


Mon, 03 Jul 2000 03:00:00 GMT  
 Date Difference function

Quote:



> > > > I thought I'd ask to see if anybody had or knew
> > > > of a VFP5.0 function that will perform a date comparison.

> > > I don't know of one, either, but it would be a useful function to have,
> > > rather than just being able to do days...
> > Have you checked GOMONTH()?

> Yes, but I was thinking more of a function that could handle anything,
> from second to year resolution. I could write it, of course, but it's
> more fun to see it installed as part of the language... :-)
> --
> Garrett Fitzgerald
> Programmer/Analyst
> UNICOM
> Providence, RI
> #INCLUDE "\Program Files\DevStudio\VFP\StdDsclm.h"

  The code snippet below my give you some ideas.

CLEAR



 VALID etime(mstartdate,mstarttime,DATE(),TIME())
READ
RETURN

PROCEDURE etime
 PARAMETERS msdate,mstime,mfdate,mftime
 edays=mfdate-msdate
 *conver start time to hours/minutes\seconds
 mshour=VAL(LEFT(mstime,2))
 msmin=VAL(SUBSTR(mstime,4,2))
 mssec=VAL(RIGHT(mstime,2))
 *conver finish time to hours/minutes\seconds
 mfhour=VAL(LEFT(mftime,2))
 mfmin=VAL(SUBSTR(mftime,4,2))
 mfsec=VAL(RIGHT(mftime,2))
 * convert to seconds from midnight
 msmid=mshour*60*60 +msmin*60+mssec
 mfmid=mfhour*60*60 + mfmin*60+mfsec
 esec=mfmid-msmid
 IF msmid>mfmid
  * event time of day less that start time of day
  * reduce day count/increase seconds
  edays=edays-1
  esec=esec+(24*60*60)
 ENDIF
 ehours =INT(esec/3600)
 emin= INT(MOD(esec,3600)/60)
 esec=INT(esec-ehours*3600-emin*60)








 RETURN



Wed, 05 Jul 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Difference() function

2. DIFFERENCE() function - need documentation

3. Difference between writing PROCEDURE and FUNCTION

4. date difference

5. Date Time differences?

6. Way to figure out number of months difference between two dates

7. Date differences between VFP 5 and VFP 6

8. date time type differences between vfp5 and vfp6

9. How to determine the difference between two dates?

10. Date Difference

11. Builtin date add function?

12. Date() functions for

 

 
Powered by phpBB® Forum Software