MySQL Function: Thai months to String
/*--------- Function: get_month ---------*/
DROP FUNCTION IF EXISTS get_month;
DELIMITER $$
CREATE FUNCTION get_month(
m VARCHAR(100)
) RETURNS int(2)
DETERMINISTIC
BEGIN
DECLARE me int(2) default 0;
IF m= 'ม.ค.' THEN set me= 1;
ELSEIF m= 'ก.พ.' THEN set me= 2;
ELSEIF m= 'มี.ค.' THEN set me= 3;
ELSEIF m= 'เม.ย.' THEN set me= 4;
ELSEIF m= 'พ.ค.' THEN set me= 5;
ELSEIF m= 'มิ.ย.' THEN set me= 6;
ELSEIF m= 'ก.ค.' THEN set me= 7;
ELSEIF m= 'ส.ค.' THEN set me= 8;
ELSEIF m= 'ก.ย.' THEN set me= 9;
ELSEIF m= 'ต.ค.' THEN set me= 10;
ELSEIF m= 'พ.ย.' THEN set me= 11;
ELSEIF m= 'ธ.ค.' THEN set me= 12;
END IF;
RETURN me;
END $$
DELIMITER ;
Comments