lnMonth = 3 lnYear = 2001 IIF(dow(date(lnYear,lnMonth,1))=1,1,9-dow(date(lnYear,lnMonth,1))) && first Sunday in month gomonth(date(lnYear,lnMonth,1),1)-date(lnYear,lnMonth,1) && no. of days in month If first Sunday + 28 days (4 more Sundays) is less < = no. of days in month, we have 5 Sunday, otherwise there are 4. So the function is: IIF((IIF(dow(date(lnYear,lnMonth,1))=1,1,9-dow(date(lnYear,lnMonth,1)))+28) <= (gomonth(date(lnYear,lnMonth,1),1)-date(lnYear,lnMonth,1)),5,4)