php 코딩 연습을 하다보니 매월초일과 말일을 자주 입력하게 된다.
그런데
‘2014-07-31’ 이렇게 되어 있던 것을 월만 바꿔서 2월로 하면 ‘2014-02-31 ‘ 이렇게 되고 strtotime() 함수를 거치면 결과적으로는 ‘2014-03-03’일이 된다.
이때 ’31’은 ’28’의 ‘오기’이기 때문에 자동으로 ‘2014-02-28’ 이라는 출력 값을 얻고 싶을 때 사용하면 좋다.
function ModiCal($date_str){
$Y_Input=substr($date_str,0,4);
$M_Input=substr($date_str,5,2);
$D_Input=substr($date_str,8,2);
$Mstrtotime=date('m',strtotime($date_str));
$dd=0;
while ($Mstrtotime>$M_Input){
$dd=$dd+1;
$Mstrtotime=date('m',strtotime($date_str. ' -' .$dd. 'days'));//
}
$D_real=$D_Input-$dd;
$date_str=$Y_Input."-".$M_Input."-".$D_real;
return $date_str;
}
소셜댓글
Warning: Attempt to read property "posts" on string in /aesop8813/www/wp-content/plugins/gplus-comments/includes/lib/frontend.php on line 64
Disqus
WordPress