Jump to content

Using only Weekdays and Excluding Weekends when calculating dates


dprichard

Recommended Posts

I have been searching trying to figure out if this is possible.  I need to figure out how many days are between certain dates excluding weekends.  Is it possible to do this.  I have tried searching google, but I guess I am not using the right keywords because the results I am getting back aren't giving me much help.  I was thinking about setting up a table and putting in all weekend dates and then pulling in that data, but thought there might be an easier way.

 

??? ??? ???

Link to comment
Share on other sites

Interesting question -- I guess there are many ways to do this.  Easiest way IMHO is to find out how many full weeks are between your dates (which means 2 weekend days), and then simply determine where the extra days are.  For example, if it's from this Wendesday to 3 Fridays from now, you have 3 full weeks (wed-wed), and no weekends between wed & fri.  make sense?

Link to comment
Share on other sites

As fenway suggested, the difference in the amount of weekends during a period will determine how many days without occur during a period... the following is a starting point that will work for a period starting and ending on a weeday that is greater than one week - Try to develop this to cater for weekend starting and ending points as well as periods shorter than one week.

SET @date_start := '2007-04-03';
SET @date_end := '2007-04-17';

SELECT datediff(@date_end, @date_start) - round(datediff(@date_end, @date_start) / 7) * 2;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.