_prev_month.sql 344 B

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