Ask the Expert

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.

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: