Program for finding difference of two dates

1333
Program for finding difference of two dates
#include<stdio.h>
#include<conio.h>
void main()
{ 
 int d1, m1, y1;     /* first date */
 int d2, m2, y2;     /* second date */
 int d, m, y;        /* difference date */
 long a, b, c;
 clrscr();
 printf("Enter first date d, m, y\n");
 scanf("%d%d%d",&d1,&m1,&y1);
 printf("enter second date d, m, y\n");
 scanf("%d%d%d",&d2,&m2,&y2);
 a=d1+(m1-1)*30+(y1-1)*365;     /* converting to total number of days 
                                     assuming 30 days in month */
 b=d2+(m2-1)*30+(y2-1)*365;
 if(a==b)
     printf("\n difference in given dates is zero\n");
 else
     {
       if(a>b)
           c=a-b;
       else
          c=b-a;     /* convert c into number of days, months and years */
          y=c/365;   /* quiescent gives number of years */
          c=c%365;   /* remainder gives number of days after making years */
          m=c/30;    /* quiescent gives number of months */
          d=c%30;    /* remainder gives number of days after making months */
   printf("\n difference in date is %4d days %4d months and %8d years", d,m,y);
      }
getch();
}
  Output 1:
  Enter first date d,m,y
  34 3 1990
  enter second date d,m.y
  22 2 2002
  difference in date is 23 days 10 months and 11 years
  Output 2:
  Enter first date d,m,y
  22 3 2006
  enter second date d,m,y
  22 3 2006
  difference in date is zero

 

 

Program for finding difference of two dates program to find difference between two dates program to find difference between two dates in c code to find difference between two dates in cc program to find difference between two dates