Software development - programming solutions

Substract an amount from a date in PHP  
substract an amount from a date (PHP4, PHP5)
//date subb, format "day.month.year hour:minutes:seconds"
//$unit can be: hr, min, sec, mon, day, year
//$amount is integer

function DateSub($data, $unit, $amount\)
{
list($arr1, $arr2)=explode(" ", $data);
list($day,$month,$year)=explode(".",$arr1);
list($hour,$minute,$second)=explode(":",$arr2);

$timestamp=mktime ($hour,$minute,$second,$month,$day,$year);
$datecomp = array("hr"=>0, "min"=>0, "sec"=>0, "mon"=>1, "day"=>1,"year"=>1970);
$datecomp[$unit] += $amount;
$diff = gmmktime($datecomp["hr"], $datecomp["min"], $datecomp["sec"], $datecomp["mon"], $datecomp["day"], $datecomp["year"]);
$newValue=$timestamp - $diff;

$newData=date("d.m.Y H:i:s", $newValue);

return $newData;
}

eXTReMe Tracker
© 1999 - 2017 (site) © 2010 - 2017 (page) Dan Mihaiu, Europe, Romania
About site statistics   About site   Copyright   Stats   Privacy Policy   Main site