I want to remove one date between three dates by function

function get_date_diff1($from,$to,$remove_dates,$check=0){
 $cDays = dateDiff($from,$to);
 $tmp=$from;
 $i=0;$o=0;$p=0;
 while($i<$cDays){
  if(in_array($tmp,$remove_dates)){
  $p=$p+1;
  }
  $tmp=strtotime($tmp)+(($i>0)?86400:0);
  $twd  =  strtolower(date("l",$tmp));
  if($twd=='sunday' || $twd=='saturday') $o=$o+1;
  $tmp = date("Y-m-d",$tmp);
  $i=$i+1;
 }
   if($check==0){
 return abs($cDays-$o-$p);
   }else{
    return abs($cDays-$p);
   }
}
echo get_date_diff1("14 April, 2014","16 April, 2014",array('14 April, 2014'));

I’m sorry for my grammar mistakes. I want to make a function which is remove the FROM or TO date between three dates and give the result of due dates. In this function when I removing the 14 April, 2014 then function work good and give the due dates (result = 2 (which I want)) but when I removing the 15 April, 2014 then function give the three due dates (result = 3) while function should be return two dates (result = 2) can someone help me where I am wrong? Thanks in Advance

Related posts

Leave a Reply

1 comment

  1. You’re passing in dates in 14 April, 2014 format, which corresponds to the PHP date() format code of d F, Y. You then build dates internally in your code in Y-m-d format. That means your in_array() call is literally trying to do

    if ('14 April, 2014' == '2014-04-14`) { ... }
    

    which will NEVER be true. You and I know they’re the same dates. PHP has NO idea they’re dates. They’re just strings, and as strings they’re NOT equal.