This topic is locked

Calculate negative days

7/18/2012 8:34:43 AM
PHPRunner General questions
S
sickacid author

Hi!! i use this code for change de background code if something are expiring (date diff between now and expiration date). But with this code if something is expired, the value of days is always positive, and the if block doesn't works. For example if something is expired than more 31 days, the result of var days is 32 and not -32.
$SC = $data["data_scadenza"];

$SG = $data["scadenza_gestita"];

$diff = abs(strtotime($SC) - strtotime(now()));

$days = floor($diff/(606024));
if ($days<32 and $SG==0)

$row["rowstyle"]='style="background:yellow"';
if ($data["scadenza_gestita"])

{

$record["edit_link"] = false;

$record["inlineedit_link"] = false;

}

C
cgphp 7/18/2012

The abs function returns the absolute value of a number:

$diff = abs(-32); //$diff = 32;