C to work out days between two dates.

I came across a nice solution to work out the time between two dates via http://stackoverflow.com .  Most the solutions I found were iterative counts through dates and leap years.  This uses the time.h functions to count from the UNIX epoch.  It required some extra details to get it to compile and function properly on my build so I thought I'd post it here.


 #include <stdio.h> 
 #include <time.h> 
  
 #define SECONDS_PER_DAY ( 24 * 60 * 60 ) 
  
 time_t timeFromDate( int year, int month, int day ) { 
     time_t rawtime; 
     struct tm * my_time; 
  
     // Create a filled in time structure 
     time( &rawtime ); 
     my_time = localtime( &rawtime ); 
      
     // Reassign our date 
     my_time->tm_year     = year - 1900; // Different sources say 1900 and 1970? 
     my_time->tm_mon        = month - 1;    // tm uses uses january + months [0..11]  
     my_time->tm_mday     = day; 
  
     // Return it as seconds since epoch 
     return( mktime( my_time ) ); 
 } 
  
 int main( void ) { 
  
     time_t start_date, end_date; 
     int days; 
  
     start_date     = timeFromDate( 2010, 1, 1 ); 
     end_date     = timeFromDate( 2010, 12, 31 ); 
  
     days = difftime( end_date, start_date) / SECONDS_PER_DAY; 
  
     printf(" Days between dates: %d\n", days ); 
  
     return 0; 
 }