file_cal_format.sql 807 B

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