1

I have this DATEDIFF query but it is not returning the result I am expecting.

SELECT 5 * ((DATEDIFF('2018-03-10', '2018-02-26') +1) DIV 7) + 
MID('0123444401233334012222340111123400012345001234550', 7 * WEEKDAY('2018-
02-26') + WEEKDAY('2018-03-10') + 1, 1)  

The result of this query should be the number working days (excluding weekend days) from start to end.

I expected an output of 10 days but instead the query returns 9. When I count the days on the calendar, I count 10 days. Anyone knows what the problem is?

Rob
  • 2,618
  • 2
  • 22
  • 29
Edwin Bermejo
  • 432
  • 3
  • 5
  • 17
  • Did you obtain this formula from somewhere else (if so, link?) or create it yourself? If the latter, what's the logic behind it? – Damien_The_Unbeliever Mar 13 '18 at 07:39
  • @Damien_The_Unbeliever Looks like it came from here: https://stackoverflow.com/questions/1828948/mysql-function-to-find-the-number-of-working-days-between-two-dates/6762805#6762805 – Peter Abolins Mar 13 '18 at 08:48
  • 1
    @PeterAbolins Yes, and had he read the whole of that answer and the subsequent comments, he'd have noticed that the solution was corrected over time to account for problems in the original version which he repeats here. – Paul Campbell Mar 13 '18 at 08:58
  • i obtained it the formula on that link, but has not read the full comments/corrections on the said formula.. sorry bout that – Edwin Bermejo Mar 13 '18 at 13:17
  • I have already corrected it, thanks and sorry. – Edwin Bermejo Mar 13 '18 at 13:20

0 Answers0