• C

Hi All,

Could you help me to calculate number of days between two dates using C.
Leap year has to be taken into consideration.
My e-mail is <email id removed by sunnycoder>

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Weiping DuSenior Web DeveloperCommented:
int month;
int day;
int year;

long int calibrate1(int yr, int mo)
     if (mo <= 2 )
       yr = yr - 1;
     return yr;
long int calibrate2 (int mo)
     if ( mo <= 2 )
        return(mo + 13);
        return(mo + 1);
long int count_days(int yr, int mo, int dy)
     return(1461 * calibrate1(yr, mo)/4 + 153 * calibrate2(mo)/5 + dy);

main ()
    long int num1;
    long int num2;

    printf("\nPlease input a date(YYYY MM DD)\n");
    scanf("%d %d %d", &year, &month, &day);

    num1 = count_days(year, month, day);

    printf ("\nPlease input 2nd date(YYYY MM DD)\n");
    scanf("%d %d %d", &year, &month, &day);

    num2 = count_days(year, month, day);

    printf ("\nThe difference is: %d\n", abs(num1-num2));
smells like an homework!!!
Weiping DuSenior Web DeveloperCommented:
very possible, I did a similar homework at 7 years ago.
PAQed - no points refunded (of 50)

E-E Admin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.