C Program to compute the difference between two dates.

Write a C program to compute the difference between two dates.In this C Program, We check the date is valid or not and then calculating the No. of days of first date and second date from Jan 1 of first date, then subtract the smaller date from another. Read more about C Programming Language .

* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* Happy Coding

void main()
int day1,mon1,year1,day2,mon2,year2;
int ref,dd1,dd2,i;
printf("Enter first date day, month, yearn");
printf("Enter second date day, month, yearn");
ref = year1;
ref = year2;
printf("nn Difference between the two dates is %d days",abs(dd2-dd1));


int dater(x)
{ int y=0;
case 1: y=0; break;
case 2: y=31; break;
case 3: y=59; break;
case 4: y=90; break;
case 5: y=120;break;
case 6: y=151; break;
case 7: y=181; break;
case 8: y=212; break;
case 9: y=243; break;
case 10:y=273; break;
case 11:y=304; break;
case 12:y=334; break;
default: printf("Invalid Inputnnnn"); exit(1);

Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

To browse more C Programs visit this link
(c) www.c-program-example.com

One comment on “C Program to compute the difference between two dates.

  • You are not taken the leap year extra day count in your dater() function.
    If u see clearly: If let say year (which is not the reference one…means greater one is a leap year)
    Try your code for dates: 16/05/2004 and 25/08/2012

    Also rather than using condition "i%4" use a proper Isleapyear check,
    For eg:
    int Isleap(int year) {
    if(((year % 4) == 0 && (year % 100) != 0) || (year % 400 == 0)) {
    return 1;
    else {
    return 0;


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>