Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculating days between two dates in C
#7
this is more about coding style
Code:
while(year1 < year2)
        {
[B]            days_in_year = if_leap(year1);
            if(days_in_year == 1)[/B]
                days_until += 366;
            else days_until += 365;
            ++year1;
        }

I'd prefer
Code:
while(year1 < year2)
        {
[B]            if(isLeap(year1))[/B]
                days_until += 366;
            else days_until += 365;
            ++year1;
        }

I could be wrong, I coded c++ before but not C



add on:
say comparing 2011 Dec 1 and 2012 Jan 1
You cannot just add 365/366 days base on the year2 > year1
Reply


Messages In This Thread
Calculating days between two dates in C - by thinbear - 2011-11-30, 03:11 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)