(Looks like something's wrong with my environment / system. Am analyzing it currently. Every logical answer was tried and it failed. So, will report back once I have more to share. Thanks for the answers!)
I have written some simple PHP code to calculate the duration between two dates, and do some basic arithmetic, to calculate some percentage value.
I am at a loss of clues on why this is not working! Seems to me that a variable is treated as an integer on one line and a string on another.
$start_DT = new DateTime($startdate); // e.g. 2011-06-07 $end_DT = new DateTime($enddate); // e.g. 2011-06-14 $today_DT = new DateTime("now"); // 2011-06-09 $duration = date_diff($end_DT, $start_DT)->d; $days_remaining = date_diff($end_DT, $today_DT)->d; echo $days_remaining; // This outputs a value of "4" in my specific case echo $duration; // This outputs a value of "7" for my specific case. $percentage_dur_complete = $days_remaining / $duration; echo $percentage_dur_complete; // This gives a value of NAN // This line says that I am dividing my zero, to imply that // $duration might be a string. $percentage_dur_complete = $days_remaining / (float) $duration; Am I missing something basic? I am a relative newbie (2 months) to PHP. I really hope (with the risk of appearing stupid) that there's something I've missed out.
Thanks!
var_dump( $myvar ), which will tell you the type and value of$myvar. More info here: php.net/manual/en/function.var-dump.phpvar_dump, then both numbers are integers and$percentage_dur_completecontains a proper number. There must be something else wrong. Are you sure$startdateand$enddateare correctly set?