home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
pcmagazi
/
1992
/
18
/
days2.prg
< prev
next >
Wrap
Text File
|
1992-06-08
|
1KB
|
42 lines
* DAYS2.PRG
* This program calculates the number of times each day of the week
* occurs within a given range of dates. dBASE IV.
*
SET TALK OFF
CLEAR
STORE CTOD(" / / ") TO beg_date,end_date
@ 3,3 SAY "Enter beginning date:" GET beg_date
@ 5,3 SAY "Enter ending date: " GET end_date
READ
?
? "Number of Sundays is " + STR(DayOccurs(beg_date,end_date,1))
? "Number of Mondays is " + STR(DayOccurs(beg_date,end_date,2))
? "Number of Tuesdays is " + STR(DayOccurs(beg_date,end_date,3))
? "Number of Wednesdays is" + STR(DayOccurs(beg_date,end_date,4))
? "Number of Thursdays is " + STR(DayOccurs(beg_date,end_date,5))
? "Number of Fridays is " + STR(DayOccurs(beg_date,end_date,6))
? "Number of Saturdays is " + STR(DayOccurs(beg_date,end_date,7))
?
RETURN
* FUNCTION DayOccurs
* Returns the number of times a day occurs in a date
* range. For example, to find how many Sundays there
* are in between 1/15/91 and 1/31/91 use:
*
* startd = CTOD("01/15/91")
* endd = CTOD("01/31/91")
* answer = DayOccurs(startd, endd, 1)
*
* 1 means Sunday, 2 means Monday etc.
*
FUNCTION DayOccurs
PARAMETERS begdate, enddate, daynumba
PRIVATE numdays, dayofw, x, result
numdays = enddate - begdate + 1
dayofw = DOW(begdate)
x = daynumba - dayofw + IIF(daynumba < dayofw,8,1)
RETURN INT(numdays/7) + IIF(x <= MOD(numdays,7),1,0)