본문 바로가기
개발/PHP

[php 함수] 두날짜 사이의 모든날짜 배열 만들기 str_replace substr checkdate

by 윤상현 2018. 12. 29.
반응형









[php 함수] 두날짜 사이의 모든날짜 배열 만들기 str_replace  substr  checkdate

[php 함수] 두날짜 사이의 모든날짜 배열 만들기 str_replace  substr  checkdate



<?


/***************************************************************************

* 두날짜 사이의 모든날짜 배열 만들기

****************************************************************************/

function dateGap($sdate,$edate){

$sdate = str_replace("-","",$sdate);

$edate = str_replace("-","",$edate);

for($i=$sdate;$i<=$edate;$i++){

$year       = substr($i,0,4);

$month substr($i,4,2);

$day     substr($i,6,2);

if(checkdate($month,$day,$year)){

$date[$year."-".$month."-".$day] = $year."-".$month."-".$day;

}

}

return $date;

}




// 모든날짜 배열 출력

echo "<pre>";

print_r(dateGap("2015-09-01", "2015-09-10"));

echo "</pre>";


echo "<br>";



?>


[ 출력 ]


Array ( [2015-09-01] => 2015-09-01 [2015-09-02] => 2015-09-02 [2015-09-03] => 2015-09-03 [2015-09-04] => 2015-09-04 [2015-09-05] => 2015-09-05 [2015-09-06] => 2015-09-06 [2015-09-07] => 2015-09-07 [2015-09-08] => 2015-09-08 [2015-09-09] => 2015-09-09 [2015-09-10] => 2015-09-10 )

반응형