Q

Function to return working days in a given month

Is there a function that will return the number of working days in a a given month? I am building a dashboard that queries my database, and I would like project sales based on a daily average MTD multiplied by the number of working days. This will change each month, so it would be nice to automate it.

This is a great question! A user defined function is a subroutine that encapsulates a piece of logic that can be reused. At a high level functions are either deterministic or nondeterministic which means they either return the same value with the same input values each time the function is called or not. SQL Server ships with a number of date and time functions that may address your needs. These functions include: GETDATE, DATEADD,...

DATEDIFF, DATEPART, etc. I would recommend reviewing these links to create your own user defined function to meet your specific application needs!

For More Information

This was first published in May 2004

Dig deeper on Microsoft SQL Server Installation

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close