DELIMITER //

CREATE FUNCTION DateDay ( date VARCHAR(8) )
RETURNS VARCHAR(10)

SQL SECURITY INVOKER
BEGIN
   DECLARE ret VARCHAR(10);
	   set ret = concat(substring(date, 1,4),'.',substring(date, 5,2),'.',substring(date, 7,2));
   RETURN ret;
END; //

DELIMITER ;