create procedure lib_timestamp_to_week_of_year ( dattim timestamp) returns ( weeknr smallint, ofyear smallint) as begin if (dattim is null) then begin weeknr = null; ofyear = null; end else begin /* week number and corresponding year relate to thursday of the concerning week (Mon ... Sun) */ dattim = dattim - extract( weekday from (dattim - 1)) /* orig: Sun = 0 ... Sat = 6 to: Mon = 0 ... Sun = 6 */ /* => Mon of week */ + 3 /* => Thu of week */; weeknr = (extract( yearday from dattim) / 7) + 1; ofyear = extract( year from dattim); end suspend; end