I am using a formula to calculate the number of days between two different days in calendar, and I am not getting the same answers as the examples I am looking at. I am trying to follow the following formula: 

N = 1461 x f(year, month) / 4 + g(month) / 5 + day

Where 
f (year, month) = year -1 if month <= 2. Otherwise the same value is returned. 
g(month) = month + 13 if month <= 2. Otherwise it is month+1.

Here is how I implemented the above formula: 

```
#include <stdio.h>
#define DEBUG

  struct date
    {
      int month ;
      int day ;
      int year ;
    };
  int een (struct date _date)
    {
      int n;
      #ifdef DEBUG
      printf("inside of een function - here is what is in date %i/%i/%i \n", _date.month, _date.day, _date.year);
      #endif
      n = 1461 * f(_date.year, _date.month) / 4 + 153 * g(_date.month) / 5 + _date.day;
      #ifdef DEBUG
      printf("Here is the value of n %i \n", n);
      #endif
      return n;
    }
  int f(int year, int month)
    {
      if (month <= 2)
      year = (year - 1);
      return year;
    }
   int g(int month)
    {
      if (month <= 2)
        month = month + 13;
      else
      month = month +1;
      return month;
    }
int main (void)
{
  struct date first_Day, second_Day;
    int days;
  int een (struct date _date);
  printf ("Enter the first date (mm dd yyyy) :");
  scanf ("%i%i%i", &first_Day.month, &first_Day.day, &first_Day.year);
  #ifdef DEBUG
  printf("Here is what you entered as the first date %i/%i/%i \n", first_Day.month, first_Day.day, first_Day.year);
  #endif
  printf ("Enter Today's date (mm dd yyyy) :");
  scanf ("%i%i%i", &second_Day.month, &second_Day.day, &second_Day.year);
  days = een (second_Day) - een (first_Day);
  printf("Here are the number of days between the dates you put in  %i \n ", days);
}

```

One example I am looking at calculates N for August 8, 2004 as follows: 

N = 1461 x f(2004, 8) / 4 + 153 x g(8) / 5 + 3 

I know the above code has some issues. I also don't know how he/she gets 3 for August 8th. I am hoping someone may have used this formula before, and they can explain if the example above is wrong or that it needs additional explanation. I have looked at other posts about this type of code, and they don't discuss my question. I have also looked into other sites, but have not been able to find the answer. I know that timeanddate.com has a calculator, and according to it, my code above does not work. 

I'll wait a bit longer to see if anyone else has used this formula before, and get some feedback. I'll then just use 12 in the g() function. 

Here are two sample calculations according to the author. For August, 8 2004 he gets: 

```
N= 1461 x f(2004, 8) / 4 + 153 x g(8) / 5 + 3 
= (1461 x 2004) / 4 + (153 x 9) / 5 + 3 
= 2,927,844 / 4 + (153 x 9) / 5 + 3
= 731,961 + 275 + 3
= 732,239

```

For Feb 22, 2005 he gets: 

```
1461 x f(2005, 2) / 4 + 153 x g(2) / 5 + 21
(1461 x 2004) / 4 + 2295 / 5 + 21 
731961 + 459 + 21 
732,441

```

Number of days in between: 731,441 - 732,239 = 202 

Frankly I am not sure how he comes up with 3 and 21 for the "day" values in the above samples. 

I also checked my answer [here](http://www.timeanddate.com/date/durationresult.html?m1=08&d1=08&y1=2004&m2=2&d2=22&y2=2005&ti=on) and it says 199 days. I think I would be ok if I could just figure out how the day variable for the above dates was calculated. I guess there is some variance, which depends on how the extra four hours in each year is treated.