home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / rettig.zip / TRSOURCE.EXE / MAKEDATE.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  1KB  |  45 lines

  1. /*********
  2. * Function: MAKEDATE 
  3. *
  4. * By: Tom Rettig
  5. *
  6. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  7. *
  8. * Syntax: MAKEDATE( <date string> [,<months>] )
  9. * Return: Valid <expD> of <date string>, even if <date string> is invalid date
  10. *         Empty <expD> if <date string> is not in the DTOS() format: "YYYYMMDD"
  11. * Note  : Calculates date with optional <months> if specified.
  12. ********/
  13.  
  14. #include "trlib.h"
  15.  
  16. TRTYPE makedate()
  17. {
  18.    char *ds;
  19.    double year, month, months;
  20.    long int day;
  21.  
  22.    if ( (PCOUNT==1 && ISCHAR(1)) ||
  23.         (PCOUNT==2 && ISCHAR(1) && ISNUM(2)) )
  24.    {
  25.       ds = _parc(1);
  26.  
  27.       if ( ISDS(ds) )
  28.       {
  29.          /* convert to numeric values */
  30.          year  = (double)   DSYEAR(ds);
  31.          month = (double)   DSMONTH(ds);
  32.          day   = (long int) DSDAY(ds);
  33.  
  34.          months = (PCOUNT==2) ? _parnd(2) : 0.0;
  35.  
  36.          _retds(  _tr_makedate( year, month+months, day ) );
  37.       }
  38.       else
  39.          _retds( BLANKDS );
  40.    }
  41.    else
  42.       _retds( BLANKDS );
  43. }
  44.  
  45.