_first_date.sql 365 B

12345678910111213141516
  1. DELIMITER //
  2. create function _first_date ( _date varchar(8) )
  3. returns VARCHAR(8)
  4. begin
  5. declare ret varchar(8);
  6. declare pmDate datetime;
  7. set pmDate = date_add(_date, interval -day(_date)+1 day);
  8. set ret = concat(substring(pmDate, 1,4),substring(pmDate, 6,2),substring(pmDate, 9,2));
  9. RETURN ret;
  10. end; //
  11. DELIMITER ;
  12. select _first_date('20220101')