# Payment due date function

This function will accept any date (@calcDate) and any given nth day (@NthDay) of the month, as an integer, for which you want to calculate a due date. First, this function will calculate the first day of the month for the passed calculation date. Second this function will determine the payment due date based on the passed nth day variable. Third, should the payment due date fall on a weekend it will automatically default to the following Monday and return the corresponding payment due date.

Example 1: If you want to calculate the 10th day of the month for October 2007 you can could write something like this:

SELECT dbo.fnPaymentDueDate(10,'10/30/2007') AS pmtDueDate

Which will return **2007-10-10 00:00:00**

Example 2: The 10th day of the month for November falls on a Saturday thus a the following example would return the due date for the following Monday like so:

SELECT dbo.fnPaymentDueDate(10,'11/25/2007') AS pmtDueDate

Which will return **2007-11-12 00:00:00**

May this function increase your productivity!

Sincerely,

Ralph Schwehr

DBA