home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_datea.prg < prev    next >
Text File  |  1994-08-29  |  2KB  |  89 lines

  1. /*
  2.     File......: GT_DateA.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Brian Dukes
  7.     Date......: 28/8/94
  8.     Revision..: 1.1
  9.  
  10.     This is an original work by Martin Bryant and is placed
  11.     in the public domain.
  12.  
  13.     Modification history:
  14.     ---------------------
  15.  
  16.     Rev 1.0 28/8/94 - PD Revision.
  17. */
  18.  
  19. /*  $DOC$
  20.  *  $FUNCNAME$
  21.  *      GT_DATEADJUST()
  22.  *  $CATEGORY$
  23.  *      Date
  24.  *  $ONELINER$
  25.  *      Take a date and add days, months and years to it
  26.  *  $SYNTAX$
  27.  *      GT_DateAdjust(<dDate>,<nDays>],[<nMonths>],[<nYears>]) -> dReturn
  28.  *  $ARGUMENTS$
  29.  *      <dDate> is a date value to which the values are
  30.  *      added.
  31.  *
  32.  *      <nDays> is the number of days to add to <dDate>.
  33.  *
  34.  *      <nMonths> is the number of months to add to <dDate>.
  35.  *
  36.  *      <nYears> is the number of years to add to <dDate>.
  37.  *  $RETURNS$
  38.  *      GT_DateAdjust() always returns a legal date.
  39.  *  $DESCRIPTION$
  40.  *      Function to take a date and add days, months and
  41.  *      years to it, returning the new date.
  42.  *  $EXAMPLES$
  43.  *      // Same date next month
  44.  *      dDate := GT_DateAdjust(DATE(),0,1,0)
  45.  *
  46.  *      // Same date a year tomorrow
  47.  *      dDate := GT_DateAdjust(DATE(),1,0,1)
  48.  *  $SEEALSO$
  49.  *
  50.  *  $INCLUDE$
  51.  *
  52.  *  $END$
  53.  */
  54.  
  55. */
  56. #include "GT_LIB.ch"
  57.  
  58. FUNCTION GT_DateAdjust(dDate,nDays,nMonths,nYears)
  59.  
  60. Local dNewDate
  61. LOCAL nMonth   := 0
  62. LOCAL nYear    := 0
  63.  
  64. Default dDate   to DATE()
  65. Default nDays   to 0
  66. Default nMonths to 0
  67. Default nYears  to 0
  68.  
  69. dNewDate := dDate + nDays
  70.  
  71. nMonth := MONTH( dNewDate ) + nMonths
  72. nYear  := YEAR(  dNewDate ) + nYears
  73.  
  74. IF nMonth < 1
  75.     nYear  -= 1
  76.     nMonth += 12
  77. ELSE
  78.     IF nMonth > 12
  79.         nYear  += 1
  80.         nMonth -= 12
  81.     ENDIF
  82. ENDIF
  83.  
  84. dNewDate := CTOD( STRZERO( DAY( dNewDate ) , 2 ) + "/" + ;
  85.                   STRZERO( nMonth , 2 )          + "/" + ;
  86.                   STRZERO( nYear , 4 ) )
  87.  
  88. RETURN dNewDate
  89.