0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

今月の何週目かを月曜日起点に計算する

Posted at
CASE(WEEKDAY(DATE(YEAR(TODAY()),MONTH(TODAY()),1)),
2,
IF(DAY(TODAY()) -1 <=6 ,  1,
IF(DAY(TODAY()) -1 <=13 , 2,
IF(DAY(TODAY()) -1 <=20 , 3,
IF(DAY(TODAY()) -1 <=27 , 4,
5)))),
3,
IF(DAY(TODAY()) -1 <=5 ,  1,
IF(DAY(TODAY()) -1 <=12 , 2,
IF(DAY(TODAY()) -1 <=19 , 3,
IF(DAY(TODAY()) -1 <=26 , 4,
5)))),
4,
IF(DAY(TODAY()) -1 <=4 ,  1,
IF(DAY(TODAY()) -1 <=11 , 2,
IF(DAY(TODAY()) -1 <=18 , 3,
IF(DAY(TODAY()) -1 <=25 , 4,
5)))),
5,
IF(DAY(TODAY()) -1 <=3 ,  1,
IF(DAY(TODAY()) -1 <=10 , 2,
IF(DAY(TODAY()) -1 <=17 , 3,
IF(DAY(TODAY()) -1 <=24 , 4,
IF(DAY(TODAY()) -1 <=31 , 5,
6))))),
6,
IF(DAY(TODAY()) -1 <=2 ,  1,
IF(DAY(TODAY()) -1 <=9 ,  2,
IF(DAY(TODAY()) -1 <=16 , 3,
IF(DAY(TODAY()) -1 <=23 , 4,
IF(DAY(TODAY()) -1 <=30 , 5,
6))))),
7,
IF(DAY(TODAY()) -1 <=1 ,  1,
IF(DAY(TODAY()) -1 <=8 ,  2,
IF(DAY(TODAY()) -1 <=15 , 3,
IF(DAY(TODAY()) -1 <=22 , 4,
IF(DAY(TODAY()) -1 <=29 , 5,
6))))),
IF(DAY(TODAY()) -1 <=0 ,  1,
IF(DAY(TODAY()) -1 <=7 ,  2,
IF(DAY(TODAY()) -1 <=14 , 3,
IF(DAY(TODAY()) -1 <=21 , 4,
IF(DAY(TODAY()) -1 <=28 , 5,
6)))))
)

考え方

月の1日が何曜日なのかによって、1日と各日の差が各週で最大値が違うことを利用する

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?