SET TERM ^ ;

create or alter function FN_INICIO_SEMANA (
    DATA date)
returns date
as
declare variable DIA_SEMANA integer;
begin
  DIA_SEMANA = extract(weekday from :DATA);
  return dateadd(day, DIA_SEMANA * -1,:DATA);
end
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER function FN_FIM_SEMANA (
    DATA date)
returns date
AS
declare variable DIA_SEMANA integer;
begin
  DIA_SEMANA = extract(weekday from :DATA);
  return dateadd(day, 6 - DIA_SEMANA,:DATA);
end
^

SET TERM ; ^

