# Difference of two dates in years, months, days Program in C

```
/*Program to get difference of two dates in years, months, days*/
#include<stdio.h>
int main(void)
{
int d1,d2,d,m1,m2,m,y1,y2,y;
printf("Enter first date(dd/mm/yyyy): ");
scanf("%d/%d/%d",&d1,&m1,&y1);
printf("Enter second date(dd/mm/yyyy): ");
scanf("%d/%d/%d",&d2,&m2,&y2);
if(d2<d1)
{
if(m2==3)
{
if(y2%100!=0 && y2%4==0 || y2%400==0) /*check for leap year*/
d2=d2+29;
else
d2=d2+28;
}
else if(m2==5 || m2==7 || m2==10 || m2==12)
d2=d2+30;
else
d2=d2+31;
m2=m2-1;
}
if(m2<m1)
{
y2=y2-1;
m2=m2+12;
}
y=y2-y1;
m=m2-m1;
d=d2-d1;
printf("Difference of the two dates is : ");
printf("%d years %d months %d days\n",y,m,d);
return 0;
}/*End of main()*/
```

#### Output:

Enter first date(dd/mm/yyyy): 03/05/1987 Enter second date(dd/mm/yyyy): 06/10/2021 Difference of the two dates is : 34 years 5 months 3 daysc language tutorial learn c language study c language

**Recent Posts**

- Print Capital String Program in Java December 31, 2021
- Fascinating Number Program in Java November 14, 2021
- Evil Number Program in Java November 14, 2021
- Insertion Sort Program in Java November 7, 2021
- Deleting Element From Array Program in Java November 7, 2021
- Adding Element In Array Program in Java November 7, 2021
- Capricorn or Kaprekar Number Program in Java October 16, 2021
- LCM and HCF of two numbers Program in C October 6, 2021
- Find day of week from a given date Program in C October 6, 2021
- Difference of two dates in years, months, days Program in C October 6, 2021
- Check whether a date is valid or not Program in C October 6, 2021
- Menu driven Program in C October 6, 2021
- Vowel or consonant Program in C October 6, 2021
- Perform arithmetic calculations on integers Program in C October 6, 2021
- Multiply two positive numbers without using "*" operator October 6, 2021
- Count digits Program in C October 6, 2021
- Product of digits Program in C October 6, 2021
- Print numbers from 1 to 10 using while loop Program in C October 6, 2021
- Find out the grade of a student Program in C October 6, 2021
- Binary Search Program in C October 2, 2021