"함수 monweek2week()"의 두 판 사이의 차이

28번째 줄: 28번째 줄:
return date('Y-\WW', strtotime("$Y-$m-4 + ".($W-1)." week"));
return date('Y-\WW', strtotime("$Y-$m-4 + ".($W-1)." week"));
}
}
$monweek = '2012-12-W5';
$monweek = '2012-12-W4';
$week = monweek2week($monweek);
$week = monweek2week($monweek);
echo $week; // 2012-W52
echo $week; // 2012-W52

2015년 7월 5일 (일) 02:10 판

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 }}