home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / disk_20.zip / BETDATE.ZIP / FOSE0007.PRG < prev   
Text File  |  1988-02-02  |  3KB  |  158 lines

  1. CLEAR
  2. CLEAR ALL
  3.  
  4. SET TALK OFF
  5. SET STATUS OFF
  6. SET SCOREBOARD OFF
  7.  
  8.  
  9. @ 4,5 TO 18,74 DOUBLE
  10. DO WHILE .T.
  11.   x = 0
  12.   y = 0
  13.   begindate = CTOD('12/25/87')
  14.   enddate = CTOD([])
  15.   @ 8,10 SAY "        Months = " + STR(X)
  16.   @ 9,10 SAY "          Days = " + STR(Y)
  17.   @ 14,10 SAY "        Months = " + STR(X)
  18.   @ 15,10 SAY "          Days = " + STR(Y)
  19.   @ 10,10 SAY "Beginning Date =  " + DTOC(begindate)
  20.   @ 11,10 SAY "   Ending Date = " GET enddate PICTURE "@D"
  21.   READ
  22.  
  23.   DO betdat WITH x,y,begindate,enddate
  24.  
  25.   @ 14,10 SAY "        Months = " + STR(X)
  26.   @ 15,10 SAY "          Days = " + STR(Y)
  27.   @ 19,1 SAY ""
  28.   WAIT TO stopit
  29.   IF stopit = "X"
  30.     EXIT
  31.   ENDIF
  32. ENDDO
  33.  
  34. CLEAR
  35.  
  36. TEXT
  37.  
  38. * Program..:  Betdates.prg
  39. * Author...:  Martin Schiff
  40. * Date.....:  February 6,1987
  41. * Notice...:  Custom Data Solutions, 1987, All rights reserved.
  42. * Notes....:  Betdates.prg
  43. *
  44. * This routine will take as input a start date and a finish date, and return
  45. * the number of months and additional days between the 2 dates.  The
  46. * routine actually figures the number of nights since it is for the travel
  47. * industry, but could be easily modified to measure the span including the
  48. * start and finish date.  The number of months is returned in tMONTHS, and
  49. * the number of days extra in tDAYS.
  50. *
  51. * If you run the program with talk set on, and you watch the dates change
  52. * using a date with 31 for the you will notice that as the program executes
  53. * you can see the last date of the month change from 31 to 30 and back, and
  54. * to 28 or 29 in February.
  55. *
  56. * This routine may be incorporated in your programs as long as the header
  57. * remains intact.
  58.  
  59. ENDTEXT
  60. WAIT
  61. CLEAR
  62. TEXT
  63.  
  64. PARAMETERS tMONTHS,tDAYS,START,FINISH
  65. holdate=start
  66. prevhold=start
  67. dofdep=finish             && dofdep -- date of departure
  68. periods=0
  69. xdays=0
  70. needtest=.f.
  71. if day(start)>28
  72.   needtest=.t.
  73. endif
  74. changed=.f.
  75. day=substr(dtoc(holdate),4,2)
  76. oldday=day
  77.  
  78. ENDTEXT
  79. WAIT
  80. CLEAR
  81. TEXT
  82.  
  83. do while holdate < dofdep
  84.   prevhold=holdate
  85.   if changed                   && if we have changed from the original day
  86.     day=oldday                 && change it back
  87.   else
  88.     day=substr(dtoc(holdate),4,2)
  89.   endif
  90.   month=substr(dtoc(holdate),1,2)
  91.   year=substr(dtoc(holdate),7,2)
  92.  
  93. ENDTEXT
  94. WAIT
  95. CLEAR
  96. TEXT
  97.  
  98. ** The following routine moves you to a date one month from the date stored
  99. ** in holdate.
  100.   if month = '12'
  101.     month='01'
  102.     year=str((val(year)+1),2)
  103.   else
  104.     if needtest              && the day of the month is > 28
  105.       if val(month)=1
  106.         changed=.t.
  107.         oldday=day
  108.         if mod(year(holdate),4)=0               && if it is a leapyear
  109.           day='29'
  110.         else
  111.           day='28'
  112.         endif
  113.       else
  114.  
  115. ENDTEXT
  116. WAIT
  117. CLEAR
  118. TEXT
  119.  
  120.         if val(day)=31
  121.           m=val(month)
  122.           if m=3 .or. m=5 .or. m=8 .or. m=10         && if prev month had 30
  123.             changed=.t.                              && days
  124.             oldday=day
  125.             day='30'
  126.           endif
  127.         endif
  128.       endif
  129.     endif
  130.     month=str((val(month)+1),2)
  131.   endif
  132.  
  133. ENDTEXT
  134. WAIT
  135. CLEAR
  136. TEXT
  137.  
  138.   holdate=ctod(month+'/'+day+'/'+year)
  139.   if holdate <= dofdep
  140.     periods=periods+1
  141.   else
  142.     xdays=dofdep-prevhold
  143.   endif
  144. enddo
  145. tmonths=periods
  146. tdays=xdays
  147.  
  148. RETURN
  149.  
  150. ENDTEXT
  151. WAIT
  152. CLEAR
  153.  
  154. SET STATUS ON
  155. SET SCOREBOARD OFF
  156. SET STATUS ON
  157. SET TALK ON
  158.