Home / EG Comp Lab / C Language / Find out difference in days between any two dates:C Program

Find out difference in days between any two dates:C Program

I am trying to take one date away from another in C and find the difference between them in days.However this is much more complicated than it first appeared to me as I obviously have to allow for differing days in different years due to leap years and a differing numbers of days depending on which month it is.

Current my data is stored as integers in array, for example,{21/1/1996 to 20/6/1996}

So could someone please post or point me towards an algorithm that will help me achieve this task?Thank you very much.

[message_box title=”Program” color=”blue”]

/*write a program to find out the difference in days between any two dates*/

/*Written by Utpal Chaudhary*/

/* Student of L.D COLLEGE OF ENGINEERING, Navrangpura, Ahmedabad-15 */



void main( )


int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};  /* Here n=28 if year is not leap otherwise n=29 */

int i ,y ,d1, d2, m1, m2, total days=0;

printf (“Enter Year:”);

scanf (“%d”,&y);

if ( ( y%4 =0  &&  y%100!=0) || (y%400==0 ) ) month[1]=29;

printf (“Enter first date: (day and month )”);

scanf (“%d %d”,&d1,M1);

printf (“Enter Second date:(day and month)”);

scanf(“%d  %d”,&d2,&m2);

totaldays=totaldays + month[m1-1]-d1;

for(i=m1, i<m2, i++)


totaldays=totaldays +month[i];


totaldays = totaldays + d2;

printf (“Total days = %d \n “,totaldays);


About Utpal

I am third year student of computer engineering in L.D COLLEGE OF ENGINEERING,Ahmedabad.

Check Also

Independent Directed Acyclic Graphs for Resilient Multipath Routing

ABSTRACT: In order to achieve resilient multipath routing, we introduce the concept of independent directed …

Leave a Reply

Be the First to Comment!

Notify of