Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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!

Sincerely,

Ralph Schwehr

DBA

Total article views: 2553 | Views in the last 30 days: 11
 
Related Articles
ARTICLE

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...

SCRIPT

Days of month function

Functions return tables with days of the specified month.

SCRIPT

Month Name

Function to return the Month Name for month number input

FORUM

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

FORUM

Best way to record payments?

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

 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones