0

the problem is simple, I have two dates and count all days between them by using datediff() function.

E.g.: datediff('23/08/2023', '30/08/2023') returns 7, but it should return 5, because 26-27/08/2023 are weekend days.

Do You know any function or have a practical solution how to count it? The simpler, the better. Thank You in advance.

adann96d
  • 41
  • 4

1 Answers1

0

This seems to be a pretty good solution.

In your case that would result in:

SELECT 
DATEDIFF(day, '2023/08/23', '2023/08/30') + 1 -
DATEDIFF(week, '2023/08/23', DATEADD(day, 1, '2023/08/30')) -
DATEDIFF(week, '2023/08/23', '2023/08/30')
AS DateDiff;

When executing this resulted in 6 weekdays which seems to be correct: 23, 24, 25, 28, 29, 30.

WLefever
  • 296
  • 2
  • 9
  • Sorry, but key words "day" and "week" are not recognized by my editor in Aqua Data Studio. DATEADD should also be replaced by DATE_ADD. – adann96d Aug 23 '23 at 13:35
  • Can you try adding single quotes or double quotes around `day` and `week`? – WLefever Aug 23 '23 at 13:54
  • I've tried and I got an error: Arguments length mismatch ''2023-08-30'': datediff() requires 2 argument, got 3 what is obvious. – adann96d Aug 23 '23 at 18:01