DELIMITER // CREATE FUNCTION DateWeek ( date VARCHAR(8) ) RETURNS VARCHAR(8) SQL SECURITY INVOKER BEGIN DECLARE month VARCHAR(5); DECLARE ret VARCHAR(8); set month = concat(substring(date, 3,2),'.',substring(date, 5,2)) ; set ret = concat(month,'-',week(date)- week(concat(substring(date, 1,6),'01'))+1); RETURN ret; END; // DELIMITER ;