home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 183_01 / datedif.c < prev    next >
Text File  |  1985-09-21  |  1KB  |  56 lines

  1. /* ******************************************************* */
  2. /*                                                         */
  3. /* This program accepts two dates in time and calculates   */
  4. /* the difference between dates.                           */
  5. /*                                                         */
  6. /* Program written by John Scarfone using Microsoft C 3.00 */
  7. /*                                                         */
  8. /* ******************************************************* */
  9.  
  10. #include <stdio.h>
  11.  
  12. main()
  13. {
  14.    long result;
  15.    long result1;
  16.    long result2;
  17.    long date();
  18.  
  19.  
  20.    printf("Datedif  ver 1.00\n");
  21.  
  22.    printf("Enter old date format yyyy mm dd ");
  23.    result1 = date();
  24.  
  25.    printf("\nEnter new date format yyyy mm dd ");
  26.    result2 = date();
  27.  
  28.    result = result2 - result1;
  29.    printf("\nThe difference between dates is %ld days.\n", result);
  30. }
  31.  
  32. long date()
  33.  
  34. {
  35.    int year;
  36.    int mon;
  37.    int day;
  38.    int n;
  39.  
  40.    n = 0l;
  41.  
  42.    scanf("%d %d %d", &year, &mon, &day);
  43.  
  44.    if (mon <= 2)
  45.     {
  46.       year = year - 1;
  47.       mon = mon + 13;
  48.     }
  49.    else
  50.       mon = mon + 1;
  51.  
  52.    n = (1461 * year) / 4 + (153 * mon) / 5 + day;
  53.  
  54.    return (n);
  55. }
  56.