drop function if exists _is_first_date; DELIMITER // create function _is_first_date ( _date varchar(8) ) returns boolean begin declare ret boolean; if substring(_date, 7,2) = '01' then set ret = true; else set ret = false; end if; return ret; end; // DELIMITER ; select _is_first_date('20220101')