home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
463.lha
/
Date_routines
/
datecmp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-04
|
1KB
|
49 lines
/*****
datecmp()
This function returns the number of days that have elapsed between
two dates. The number of days between Jan. 1 (1) and Nov. 11 (315)
in a non-leap year is treated as 314. If you disagree, you can change
this function accordingly.
Argument list: int d1 the day for year 1
int m1 " month "
int y1 " year "
int d1 the day for year 2
int m1 " month "
int y1 " year "
Return value: unsigned int the number of days from date1 to date2
*****/
#include <stdlib.h>
unsigned int datecmp(int d1, int m1, int y1, int d2, int m2, int y2)
{
int i, max, min, t1, t2, years = 0;
t1 = julian(d1, m1, y1);
t2 = julian(d2, m2, y2);
if (y1 != y2) { /* Must go across years */
if (y1 > y2) {
max = y1;
min = y2;
t2 = julian(31, 12, y2) - t2; /* Days to end of year */
} else {
max = y2;
min = y1;
t1 = julian(31, 12, y2) - t1;
}
for (i = max; i > min + 1; i--) { /* For all years */
years += 365 + leapyear(i);
}
} else {
t1 = julian(d1, m1, y1);
t2 = julian(d2, m2, y2);
return (abs(t1 - t2));
}
return (t1 + t2 + years + 1);
}