Tuesday, March 12, 2013

C Language Example # 36 Find Date Difference : Date Difference Month wise


C Language Example # 36 Find Date Difference : Date Difference Month wise.

* Program will find date difference between two dates.
* You just need to enter to date in dd mm yyyy format..


//Written by Latest Technology Guide   

 //Title : C Language Example # 36 Find Date Difference : Date Difference Month wise.


#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int d1,m1,y1,d2,m2,y2,i,temp,sum=0,month[]={31,28,31,30,31,30,31,31,30,31,30,31};

printf("Enter Date 1 : (DD-MM-YYYY) :");
scanf("%d %d %d",&d1,&m1,&y1);

printf("Enter Date 2 : (DD-MM-YYYY) :");
scanf("%d %d %d",&d2,&m2,&y2);

temp=d1;

for(i=m1;i<m2+(y2-y1)*12;i++)
{
if(i>12)
{
i=1;
y1++;
}

if(i==2)
{
if(y1%4==0 && (y1%100!=0 || y1%400==0))
month[i-1]=29;
else
month[i-1]=28;
}

sum=sum+(month[i-1]-temp);
temp=0;

printf("Month = %d\t Days = %d\t Sum = %d\n",i,month[i-1],sum);

if(i%12==0)
getch();

}

sum=sum+d2-temp;

printf("\n Total Number of Days are : %5d",sum);
getch();
}


Output:




--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 36 Find Date Difference : Date Difference Month wise.

* You need to enter two date as per the format i.e. DD MM YYYY. one date is from date and another one is to date. 
* Then program will calculate difference and will display monthly summary.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

No comments:

Post a Comment