Created
April 22, 2012 14:19
-
-
Save cpylua/2464302 to your computer and use it in GitHub Desktop.
computing the day difference between two dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this code is from http://c-faq.com/lib/calendar.br.html */ | |
#define DayOfWeek(d,m,y) (int)(DaysElapsed(d,m,y) % 7) | |
long DaysElapsed(int d,int m,int y) { | |
static int cd[]={0,31,59,90,120,151,181,212,243,273,304,334}; | |
long n=365L*(y-1); | |
if (m<3) y--; | |
return n+y/4-y/100+y/400+cd[m-1]+d; | |
} | |
difference=DaysElapsed(d2,m2,y2)-DaysElapsed(d1,m1,y1); | |
/** | |
* Here are some long explanations: | |
* http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html | |
* http://alcor.concordia.ca/~gpkatch/gdate-method.html | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment