salix/db/routines/vn/functions/lastDayOfWeek.sql

25 lines
478 B
MySQL
Raw Permalink Normal View History

DELIMITER $$
2024-08-20 08:06:10 +00:00
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`lastDayOfWeek`(vYear INT, vWeek INT)
RETURNS date
DETERMINISTIC
BEGIN
/**
* Returns the date of the last day of the week
*
* @param vYear The year
* @param vWeek The week number
* @return Date of the first day of the week
*/
DECLARE vDate DATE;
SELECT dated INTO vDate
FROM `time`
WHERE `year` = vYear
AND `week` = vWeek
ORDER BY dated DESC
LIMIT 1;
RETURN vDate;
END$$
DELIMITER ;