์ƒˆ์†Œ์‹

๐Ÿ“šStudy/ETC

[MariaDB] ์›” ์ค‘ ์ฃผ์ฐจ ๊ตฌํ•˜๊ธฐ WeekOfMonth

  • -

 

 

๋‚ด์šฉ

์ •์‚ฐ ํŽ˜์ด์ง€์˜ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆฌ๊ธฐ ์œ„ํ•ด ์›” ์ค‘ ์ฃผ์ฐจ๋ฅผ ๊ตฌํ•˜๋Š” Function ์ด ํ•„์š”ํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค.

์•„์‰ฝ๊ฒŒ๋„ MariaDB์— ๋‚ด์žฅ๋œ ํ•จ์ˆ˜ ์ค‘์— WEEKOFMONTH ๋Š” ์—†์–ด์„œ SELECT ๋ฌธ์œผ๋กœ ๊ตฌํ˜„ํ•˜์˜€๋‹ค.

 

 

SELECT CEILING((DAY(NOW()) - (6 - WEEKDAY(DATE_FORMAT(NOW(), '%Y-%m-01')))) / 7)
           + CASE
                 WHEN 6 - WEEKDAY(DATE_FORMAT(NOW(), '%Y-%m-01')) > 0 THEN 1
                 ELSE 0 END WEEK_OF_MONTH;

 



๋ฐ˜์‘ํ˜•
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.