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

잔글 (Jmnote 사용자가 함수 monweek2week 문서를 함수 monweek2week() 문서로 옮겼습니다)
22번째 줄: 22번째 줄:
==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='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-W5';
$week = monweek2week($monweek);
echo $week; // 2012-W52
</source>
<source lang='php'>
<source lang='php'>
function monweek2week($monweek) {
function monweek2week($monweek) {
27번째 줄: 37번째 줄:
return substr($monweek,0,4)."-W$weeknum";
return substr($monweek,0,4)."-W$weeknum";
}
}
$monweek = '2012-12-W4';
$week = monweek2week($monweek);
echo $week; // 2012-W52
</source>
</source>


==같이 보기==
==같이 보기==
*[[함수 week2monweek]]
*[[함수 week2monweek]]

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

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-W5';
$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 }}