SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Payment due date function

By Ralph Schwehr,

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!


Ralph Schwehr


Total article views: 2581 | Views in the last 30 days: 7
Related Articles

Calculating Stock Returns Using the ROW_NUMBER function and CTEs

In finance, when pricing data isn't available on last day of week, month or year, calculating return...


Days of month function

Functions return tables with days of the specified month.


Month Name

Function to return the Month Name for month number input


I need to create a function that returns a date 6 months from getutc date

I need to create a function that returns a date 6 months from getutc date


Best way to record payments?

Accept Checks, Credit Card, cash, partial payments, over payments...