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.

 

??? ??? ???

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?

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;

Archived

This topic is now archived and is closed to further replies.

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