Scripts and functions that I have written or found useful

strtotime that accepts dates

February 7th, 2008 Posted in PHP

I got tired of writing many lines of code to simply add x amount of time onto a given date due to having to workout the linux timestamp for a certain date, then adding the date, then converting it back for next time so I wrote this…

Basically, it works in the same wasas strtotime() except that it requests a date rather than a timestamp.

//stringtotime(”+2 days”,”2008-02-07″);
function stringtotime($duration,$date)
{
$y = substr($date,0,4);
$m = substr($date,5,2);
$d = substr($date,8,2);
$timestamp = mktime(0,0,0,$m,$d,$y);
$newtimestamp = strtotime(”+ $duration days”,$timestamp);
$newdate = date(”Y-m-d”,$newtimestamp);
return $newdate;

}

Post a Comment