file_cal_format.sql 828 B

12345678910111213141516171819202122232425262728293031
  1. DROP PROCEDURE IF EXISTS fill_cal_format;
  2. DELIMITER |
  3. CREATE PROCEDURE fill_cal_format(dateStart DATE, dateEnd DATE)
  4. SQL SECURITY INVOKER
  5. BEGIN
  6. declare i date ;
  7. declare w int;
  8. set i = dateStart ;
  9. WHILE i <= dateEnd DO
  10. set w = week(i);
  11. IF weekday(i) = 0 THEN
  12. INSERT INTO dbr_cal_format(date_type, date_index)
  13. VALUES ('week', concat( DATE_FORMAT(dateStart, '%y.%m'), '-', if(length(w) = 1, concat('0',w), w) ));
  14. END IF;
  15. IF DATE_FORMAT(i, '%d') = '01' THEN
  16. INSERT INTO dbr_cal_format(date_type, date_index)
  17. VALUES ('month', DATE_FORMAT(i, '%y.%m'));
  18. END IF;
  19. INSERT INTO dbr_cal_format(date_type, date_index)
  20. VALUES ('day', DATE_FORMAT(i, '%Y%m%d'));
  21. SET i = date_add(i, INTERVAL 1 DAY);
  22. END WHILE;
  23. END;
  24. |
  25. DELIMITER ;
  26. CALL fill_cal_format('2021-01-01','2021-12-31');