home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / disk_20.zip / BETDATE.ZIP / BETDAT.PRG next >
Text File  |  1987-02-21  |  3KB  |  84 lines

  1. * Program..:  Betdates.prg
  2. * Author...:  Martin Schiff
  3. * Date.....:  February 6,1987
  4. * Notice...:  Custom Data Solutions, 1987, All rights reserved.
  5. * Notes....:  Betdates.prg 
  6. * This routine will take as input a start date and a finish date, and return
  7. * the number of months and additional days between the 2 dates.  The
  8. * routine actually figures the number of nights since it is for the travel
  9. * industry, but could be easily modified to measure the span including the 
  10. * start and finish date.  The number of months is returned in tMONTHS, and
  11. * the number of days extra in tDAYS.
  12. * If you run the program with talk set on, and you watch the dates change
  13. * using a date with 31 for the you will notice that as the program executes
  14. * you can see the last date of the month change from 31 to 30 and back, and
  15. * to 28 or 29 in February.
  16. *
  17. * This routine may be incorporated in your programs as long as the header 
  18. * remains intact.
  19.  
  20. PARAMETERS tMONTHS,tDAYS,START,FINISH
  21. holdate=start
  22. prevhold=start
  23. dofdep=finish             && dofdep -- date of departure
  24. periods=0
  25. xdays=0
  26. needtest=.f.
  27. if day(start)>28
  28.   needtest=.t.
  29. endif
  30. changed=.f.
  31. day=substr(dtoc(holdate),4,2)    
  32. oldday=day
  33. do while holdate < dofdep    
  34.   prevhold=holdate    
  35.   if changed                   && if we have changed from the original day
  36.     day=oldday                 && change it back
  37.   else
  38.     day=substr(dtoc(holdate),4,2)    
  39.   endif
  40.   month=substr(dtoc(holdate),1,2)    
  41.   year=substr(dtoc(holdate),7,2)    
  42. ** The following routine moves you to a date one month from the date stored
  43. ** in holdate.
  44.   if month = '12'    
  45.     month='01'    
  46.     year=str((val(year)+1),2)    
  47.   else    
  48.     if needtest              && the day of the month is > 28
  49.       if val(month)=1    
  50.         changed=.t.    
  51.         oldday=day    
  52.         if mod(year(holdate),4)=0               && if it is a leapyear
  53.           day='29'        
  54.         else        
  55.           day='28'        
  56.         endif        
  57.       else    
  58.         if val(day)=31    
  59.           m=val(month)    
  60.           if m=3 .or. m=5 .or. m=8 .or. m=10         && if prev month had 30
  61.             changed=.t.                              && days
  62.             oldday=day    
  63.             day='30'    
  64.           endif    
  65.         endif    
  66.       endif        
  67.     endif
  68.     month=str((val(month)+1),2)          
  69.   endif          
  70.   holdate=ctod(month+'/'+day+'/'+year)          
  71.   if holdate <= dofdep          
  72.     periods=periods+1          
  73.   else          
  74.     xdays=dofdep-prevhold
  75.   endif          
  76. enddo        
  77. tmonths=periods      
  78. tdays=xdays      
  79.  
  80. RETURN      
  81.  
  82.    ......................... ... ... ....1200 N81N         ......................... ... ... ....1200 N81N         ......................... ... ... ....1200 N81N         ......................... ... ... ....1200 N81N         ............