home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 463.lha / Date_routines / datecmp.c < prev    next >
C/C++ Source or Header  |  1991-01-04  |  1KB  |  49 lines

  1. /*****
  2.                               datecmp()
  3.  
  4.       This function returns the number of days that have elapsed between
  5.    two dates.  The number of days between Jan. 1 (1) and Nov. 11 (315)
  6.    in a non-leap year is treated as 314. If you disagree, you can change
  7.    this function accordingly.
  8.  
  9.    Argument list:    int d1         the day for year 1
  10.                      int m1          "  month   "
  11.                      int y1          "  year    "
  12.                      int d1         the day for year 2
  13.                      int m1          "  month   "
  14.                      int y1          "  year    "
  15.  
  16.    Return value:     unsigned int   the number of days from date1 to date2
  17.  
  18. *****/
  19.  
  20. #include <stdlib.h>
  21.  
  22. unsigned int datecmp(int d1, int m1, int y1, int d2, int m2, int y2)
  23. {
  24.    int i, max, min, t1, t2, years = 0;
  25.  
  26.    t1 = julian(d1, m1, y1);
  27.    t2 = julian(d2, m2, y2);
  28.  
  29.    if (y1 != y2) {                        /* Must go across years */
  30.       if (y1 > y2) {
  31.          max = y1;
  32.          min = y2;
  33.          t2 = julian(31, 12, y2) - t2;    /* Days to end of year  */
  34.       } else {
  35.          max = y2;
  36.          min = y1;
  37.          t1 = julian(31, 12, y2) - t1;
  38.       }
  39.       for (i = max; i > min + 1; i--) {   /* For all years        */
  40.          years += 365 + leapyear(i);
  41.       }
  42.    } else {
  43.      t1 = julian(d1, m1, y1);
  44.      t2 = julian(d2, m2, y2);
  45.      return (abs(t1 - t2));
  46.    }
  47.    return (t1 + t2 + years + 1);
  48. }
  49.