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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
22번째 줄: 22번째 줄:
==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
function monweek2week($monweek) {
function monweek2week($monweek) {
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
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
function monweek2week($monweek) {
function monweek2week($monweek) {
$weeknum = str_pad(date('W', strtotime(substr($monweek,0,7).'-4'))+substr($monweek,-1)-1, 2, '0', STR_PAD_LEFT);
$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";
return substr($monweek,0,4)."-W$weeknum";
}
}
</source>
</syntaxhighlight>


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

2020년 11월 2일 (월) 02:36 기준 최신판

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