DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`MIDNIGHT`(vDate DATE) RETURNS datetime DETERMINISTIC BEGIN RETURN TIMESTAMP(vDate,'23:59:59'); END$$ DELIMITER ;