SQL generate_series, dayofweek(DOW), weekday, functions

SQL

https://www.codewars.com/kata/58241d05e7a162c5b100010f/train/sql

-- Replace with your code
CREATE OR REPLACE FUNCTION weekdays(DATE,DATE)
  RETURNS INTEGER AS
$func$
SELECT COUNT(*)
FROM GENERATE_SERIES(LEAST($1,$2),GREATEST($1,$2),'1d') AS days
WHERE EXTRACT(ISODOW FROM days) < 6
$func$
LANGUAGE sql;
Did you find this snippet useful?

Sign up for free to to add this to your code library

median
SQL

5
SQL RANK
SQL

5
EXISTS
SQL

4