Create date from day, month, year fields in MySQL

后端 未结 6 1007
予麋鹿
予麋鹿 2020-12-05 22:25

I am currently developing an application that displays documents and allows the members to search for these documents by a number of different parameters, one of them being

6条回答
  •  情话喂你
    2020-12-05 23:14

    Expanding this answer, here's my take on it:

    DELIMITER $$
    
    CREATE FUNCTION fn_year_month_to_date(var_year INTEGER,
        var_month enum('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12')
        )
    RETURNS DATE
    BEGIN
        RETURN (MAKEDATE(var_year, 1) + INTERVAL (var_month - 1) MONTH);
    END $$
    
    DELIMITER ;
    
    SELECT fn_year_month_to_date(2020, 12)
    ;
    

提交回复
热议问题