Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
CREATE FUNCTION get_weekends_count(p_from_date date, p_to_date date) RETURNS integer LANGUAGE plpgsql AS $$ DECLARE _count integer := 0; _d date := p_from_date; BEGIN WHILE _d <= p_to_date LOOP IF to_char(_d, 'DY') = 'SAT' OR to_char(_d, 'DY') = 'SUN' THEN _count = _count + 1; END iF; _d = _d + interval '1 day'; END LOOP; RETURN _count; END; $$; select get_weekends_count('2023-04-01'::date, '2023-04-30'::date);

Stuck with a problem? Got Error? Ask AI support!

Copy Clear