PHP Convert Datetime DB fields to timespan


< ?php 
	  
	  $curentdate=mktime(date("h"), date("i"), date("s"), date("m")  , date("d"), date("Y"));
	  $curentdatestart=mktime(date("h",strtotime($row_ekpompes['ext_series_trailer_startdate'])), date("i",strtotime($row_ekpompes['ext_series_trailer_startdate'])), date("s",strtotime($row_ekpompes['ext_series_trailer_startdate'])), date("m",strtotime($row_ekpompes['ext_series_trailer_startdate']))  , date("d",strtotime($row_ekpompes['ext_series_trailer_startdate'])), date("Y",strtotime($row_ekpompes['ext_series_trailer_startdate'])));
	  $curentdateend=mktime(date("h",strtotime($row_ekpompes['ext_series_trailer_enddate'])), date("i",strtotime($row_ekpompes['ext_series_trailer_enddate'])), date("s",strtotime($row_ekpompes['ext_series_trailer_enddate'])), date("m",strtotime($row_ekpompes['ext_series_trailer_enddate']))  , date("d",strtotime($row_ekpompes['ext_series_trailer_enddate'])), date("Y",strtotime($row_ekpompes['ext_series_trailer_enddate'])));
	// strtotime
	 if($row_ekpompes['ext_series_trailer_startdate']!=null && $row_ekpompes['ext_series_trailer_enddate']!=null && $row_ekpompes['ext_series_trailer']!=null){
	 if($curentdatestart<=$curentdate &&  $curentdateend>=$curentdate ){
	 $video=$row_ekpompes['ext_series_trailer'];
	 }else {
	 $video=$row_ekpompes['ext_trailer'];
	 }
	 }else {
	 $video=$row_ekpompes['ext_trailer'];
	 }
	 echo $video."====";
	 echo date('h:i:s / m/d/y');
	 echo "===".$curentdate."---".$curentdatestart."---".$curentdateend;
	 echo  $row_now['ext_trailer']."----";
	 echo  $row_now['ext_series_trailer']."----";
         echo  $row_now['ext_series_trailer_startdate']."----";
	 echo  $row_now['ext_series_trailer_enddate']."----";
	  
	  ?>

Leave a comment