I second Matt T Heffron. Do it in code instead of database.
Since I didn't understand your requirement very well, here's an example of working with
DateTime[
^] coded at my whim:
void ShowExample()
{
DateTime salaryDay = DateTime.Now;
DateTime monthStart = new DateTime(salaryDay.Year, salaryDay.Month, 1);
int daysInMonth = DateTime.DaysInMonth(salaryDay.Year, salaryDay.Month);
DateTime monthEnd = new DateTime(salaryDay.Year, salaryDay.Month, daysInMonth);
int sundays = 0;
for (DateTime dt = monthStart; dt < monthEnd; dt += TimeSpan.FromDays(1))
{
if (dt.DayOfWeek == DayOfWeek.Sunday)
{
sundays++;
}
}
}