함수 monweek2week()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:36 판 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

monweek to week
  • YYYY-Www → YYYY-MM-Ww
  • ISO-8601
  • test set
2012-01-W1 → 2012-W01
2012-03-W3 → 2012-W11
2012-12-W4 → 2012-W52

2 Excel[ | ]

2.1 1 cell[ | ]

=TEXT(DATE(LEFT(A1,4),MID(A1,6,2),4)+7*(RIGHT(A1,1)-1),"YYYY")&"-W"&TEXT(INT((DATE(LEFT(A1,4),MID(A1,6,2),4)+7*(RIGHT(A1,1)-1)-DATE(YEAR(DATE(LEFT(A1,4),MID(A1,6,2),4)+7*(RIGHT(A1,1)-1)-WEEKDAY(DATE(LEFT(A1,4),MID(A1,6,2),4)+7*(RIGHT(A1,1)-1)-1)+4),1,3)+WEEKDAY(DATE(YEAR(DATE(LEFT(A1,4),MID(A1,6,2),4)+7*(RIGHT(A1,1)-1)-WEEKDAY(DATE(LEFT(A1,4),MID(A1,6,2),4)+7*(RIGHT(A1,1)-1)-1)+4),1,3))+5)/7),"00")

2.2 2 cells[ | ]

  • B1
=DATE(LEFT(A1,4),MID(A1,6,2),4)+7*(RIGHT(A1,1)-1)
  • C1
=TEXT(B1,"YYYY")&"-W"&TEXT(INT((B1-DATE(YEAR(B1-WEEKDAY(B1-1)+4),1,3)+WEEKDAY(DATE(YEAR(B1-WEEKDAY(B1-1)+4),1,3))+5)/7),"00")

3 PHP[ | ]

<?php
function monweek2week($monweek) {
	list($Y, $m, $W) = sscanf($monweek, "%d-%d-W%d");
	return date('Y-\WW', strtotime("$Y-$m-4 + ".($W-1)." week"));
}
$monweek = '2012-12-W4';
$week = monweek2week($monweek);
echo $week; // 2012-W52
function monweek2week($monweek) {
	$weeknum = str_pad(date('W', strtotime(substr($monweek,0,7).'-4'))+substr($monweek,-1)-1, 2, '0', STR_PAD_LEFT);
	return substr($monweek,0,4)."-W$weeknum";
}

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}