Home mysql adddate no weekends
Reply: 0

mysql adddate no weekends

pipechaves Published in 2018-01-12 21:18:20Z

first of all i know that this has been asked before, and there are some really good answers, but not 100% correct, since my reputation is low I can't post comments. My question is how to add days in MySQL excluding weekends, for example the day 1/8/2018 if we add 20 days the results should be 1/29/2018, most of the forum answers are like the following

SELECT StartDate,Expected Date,DATE_FORMAT( DATE_ADD(StartDate, INTERVAL Expected Date +

IF( (WEEK(StartDate) <> WEEK(DATE_ADD(StartDate, INTERVAL Expected Date DAY))) OR (WEEKDAY(DATE_ADD(StartDate, INTERVAL Expected Date DAY)) IN (5, 6)),
IF( Expected Date >0, 2, -2 ), 0) DAY ) , '%y-%m-%d') as FinalDate from table,

THIS WORKS but for low numbers where it will encounter just one weekend, I do change the formula to accept minus add days. I know the tricky part is around IF( Expected Date >0, 2, -2 ), where it add or delete more days if its weekend, but cant find a way to figure it out if there are more than 1 weekend in between.

i hope I make my self clear and some could help me.

Similar post but not 100% right Here

Thank you

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314148 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO