PHP change date

03.Jul.2010

If you want to use PHP to change date.

1
2
3
4
5
6
function php_change_date($number_of_days, $from_date) {
	$date = new DateTime();
	$date->setDate($from_date);
	$date->modify($number_of_days . ' days');
	return $date->format("Y-m-d");
}

Example of usage:

You want to know what will be date in 40 days from now, you will use PHP change date like:

echo php_change_date('+40', date('Y-m-d'));

If you want to know what was the date 10 days ago, you will use PHP change date like:

echo php_change_date('+10', date('Y-m-d'));