Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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.
0
Oster
Asked:
Oster
  • 2
1 Solution
 
owenli27Commented:
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);
     else
        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));
}
0
 
sarda_rameshCommented:
smells like an homework!!!
0
 
owenli27Commented:
very possible, I did a similar homework at 7 years ago.
0
 
Computer101Commented:
PAQed - no points refunded (of 50)

Computer101
E-E Admin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now