home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
PROGRAMM
/
SNIP0492.ZIP
/
DAYNUM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-19
|
1KB
|
56 lines
/*
** DAYNUM.C - Functions to return statistics about a given date.
**
** public domain by Bob Stout - uses Ray Gardner's SCALDATE.C
*/
long ymd_to_scalar (unsigned yr, unsigned mo, unsigned day);
static long jan1date;
/*
** Return the day of the year (1 - 365/6)
*/
int daynum(int year, int month, int day)
{
jan1date = ymd_to_scalar(year, 1, 1);
return (int)(ymd_to_scalar(year, month, day) - jan1date + 1L);
}
/*
** Return the week of the year (1 - 52)
*/
int weeknum(int year, int month, int day)
{
int dn = daynum(year, month, day);
dn += (int)(jan1date % 7L) - 1;
return(1 + (dn / 7));
}
#ifdef TEST
#include <stdio.h>
void do_err(void);
void main(int argc, char *argv[])
{
int day, month, year;
if (4 > argc)
{
puts("Usage: DAYNUM month day year");
return;
}
month = atoi(argv[1]);
day = atoi(argv[2]);
year = atoi(argv[3]);
printf("%d/%d/%d is day #%d in week %d\n", month, day, year,
daynum(year, month, day), weeknum(year, month, day));
}
#endif /* TEST */