_prev_month.sql 381 B

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