Posts Tagged ‘PHP’

Simple PHP Dates

I’ve seen people ask how to do future and past dates,  so here’s what I use.

function doDate($when, $days){
if($when==’past’){
echo date(‘l, F j, Y’, time() – 86400 * $days);
}else if($when==’future’){
echo date(‘l, F j, Y’, time() + 86400 * $days);
}
}
Usage: <?php doDate(‘[past/future]‘,[number of days]); ?>
Example: <?php doDate(‘past’,3); ?>
This will show a date either in the past or future [...]