'php'에 해당되는 글 1건

  1. 2008.06.20 [날짜] 시작일~종료일 사이의 날짜 출력
JOB/PHP2008. 6. 20. 15:30

$date_1 = "2008-05-29"; //시작일
$date_2 = "2008-06-10"; //종료일

$d1_data = explode("-",$date_1);
$d2_data = explode("-",$date_2);

$data1_str = " " . "$d1_data[1]" . "/" . "$d1_data[2]" . "/" . "$d1_data[0]";
$data2_str = " " . "$d2_data[1]" . "/" . "$d2_data[2]" . "/" . "$d2_data[0]";

$d1_strtotime = strtotime($data1_str);
$d2_strtotime = strtotime($data2_str);



while($d1_strtotime != $d2_strtotime){
                                    
$d1_strtotime = strtotime("+1 day",$d1_strtotime);
                                        
print $sing=date("Y-m-d",$d1_strtotime) . "<br>";

}

//RESULT
2008-05-30
2008-05-31
2008-06-01
2008-06-02
2008-06-03
2008-06-04
2008-06-05
2008-06-06
2008-06-07
2008-06-08
2008-06-09
2008-06-10


===============================================================================

$date_1 = "2008-05-29";
$date_2 = "2008-06-02";

$d1_data = explode("-",$date_1);
$d2_data = explode("-",$date_2);

$data1_str = " " . "$d1_data[1]" . "/" . "$d1_data[2]" . "/" . "$d1_data[0]";
$data2_str = " " . "$d2_data[1]" . "/" . "$d2_data[2]" . "/" . "$d2_data[0]";

$d1_strtotime = strtotime($data1_str);
$d2_strtotime = strtotime($data2_str);

$d1_strtotime = strtotime("-1 day",$d1_strtotime);

 

while($d1_strtotime != $d2_strtotime){
                                    
 $d1_strtotime = strtotime("+1 day",$d1_strtotime);
                                        
echo $sing=date("Y-m-d",$d1_strtotime) . "<br>";


}
//RESULT
2008-05-29
2008-05-30
2008-05-31
2008-06-01
2008-06-02

Posted by webfeel