This question already has an answer here:
$diff = strtotime( date("Y-m-d",strtotime($row->Released_Date)) ) - strtotime( date("Y-m-d",strtotime($CommitmentDate)));
$days = intval(round($diff/86400));
$s = $days > 1 ? 's' : '';
$status = $days > 0 ? '<i class="fa fa-exclamation" original-title="Day'.$s.' lapsed - '.$days.'<br><i>'.date("F d, Y",strtotime($CommitmentDate)).'</i>"></i>' :
$days = 0 ? '<i class="fa fa-check" original-title="RELEASED ON TIME<br><i>'.date("F d, Y",strtotime($CommitmentDate)).'</i>"></i>' :
'<i class="fa fa-star" original-title="RELEASED BEFORE COMMITMENT DATE<br><i>'.date("F d, Y",strtotime($CommitmentDate)).'<br>'.$days.'</i>"></i>';
there's one $days that returns zero but it seems it didnt output an exact zero because i didnt see check sign...
i really dont know whats wrong...
i used
$days = intval(round($diff/86400));
$days = int(round($diff/86400);
i tried $days = intval($diff/86400);
its returning exact ZERO but i dont know why THE OUTPUT SAYING ITS LESS THAN ZERO
this is the output... the number on end is the output of $days...
enter image description here enter image description here
PLEASE HELP....
</div>
You are assigning $days=0
you must use ==
operator to compare,
$days == 0 ? '<i class="fa fa-check" original-title="RELEASED ON TIME....
One more thing you can just use single time strtotime
to get the difference like,
// no need to convert it in date then again in strtotime
$diff = strtotime( $row->Released_Date ) - strtotime($CommitmentDate);
Updated, you need to enclose the else part in ()
otherwise it will not return the result as expected like,
$status = $days > 0 ? '<i class="fa fa-exclamation" original-title="Day'.$s.' lapsed - '.$days.'<br><i>'.date("F d, Y",strtotime($CommitmentDate)).'</i>"></i>' :
($days == 0 ? '<i class="fa fa-check" original-title="RELEASED ON TIME<br><i>'.date("F d, Y",strtotime($CommitmentDate)).'</i>"></i>' :
//--^ start enclosing here, with $days == 0 condition
'<i class="fa fa-star" original-title="RELEASED BEFORE COMMITMENT DATE<br><i>'.
date("F d, Y",strtotime($CommitmentDate)).'<br>'.$days.'</i>"></i>');
// -- to here -----------^
Try this
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
$days = $interval->format('%a');
$daySec = $day * 86400;