* Program....: SUNINMONTH.PRG * Version....: 1.0 * Author.....: Andrew Coates * Date.......: March 22, 2001 * Notice.....: Copyright © 2001 Civil Solutions, All Rights Reserved. * Compiler...: Visual FoxPro 06.00.8961.00 for Windows * Abstract...: Establishes the number of Sundays in a given month * optionally pass the month (1-12) (assumes the current month) and the * year (100 - 9999) (assumes the current year) * Changes....: lparameters tnMonth, tnYear local lnMonth, lnYear if vartype(tnMonth) # 'N' or ! between(tnMonth, 1, 12) lnMonth = month(date()) else lnMonth = int(tnMonth) endif * date() takes year between 100 and 9999 if vartype(tnYear) # 'N' or ! between(tnYear, 100, 9999) lnYear = year(date()) else lnYear = int(tnYear) endif * get the first day in the month local lnFirstDay, ldFirstDayDate ldFirstDayDate = date(lnYear, lnMonth, 1) * what day is the first day * note that the dow() function uses Sunday = 1 unless a second parameter is passed, * regardless of the regional settings * we'll use sunday = day 7 (Monday = 1) for this calc as it makes things easier lnFirstDay = dow(ldFirstDayDate, 2) * work out the number of days in the month (and therefore the number of extra days over 4 weeks) lnDaysInMonth = gomonth(ldFirstDayDate, 1) - ldFirstDayDate lnExtraDays = lnDaysInMonth - 28 * For there to be an extra sunday, lnFirstDay must fall on a Sunday (for 29 day month), * a Saturday or a Sunday (for 30 day month) or on a * Friday, Saturday or Sunday (for a 31 day month) * so the first day has to be be between (7 - lnExtraDays + 1) and 7 lnSundays = 4 + iif(between(lnFirstDay, (7 - lnExtraDays + 1),7), 1, 0) return lnSundaysCheers,
>FUNCTION countSundays >LPARAMETERS pnYear, pnMonth >LOCAL ldDate1, ldDate2 >ldDate1 = date(pnYear, pnMonth, 1) >ldDate2 = gomonth(ldDate1, 1) > >return int((d2-d1+dow(d1)) / 7) >ENDFUNC >>