As you probably know php gives you a nice date() function that allows you to get a date and format it using a vast amount of unix date strings. But what if you want to add/subtract days, weeks and months to a date? Marty, warm up the delorean…

Nerd jokes aside…for the mean time. You can add any amount of time to a date in php using the strtotime function, this will allow manipulation of a date once it has been converted to a unix time string. See the example below:

$today = date("Y-m-d"); // current date

$tomorrow = strtotime(date("Y-m-d", strtotime($today)) . " +1 day");
$output = date("Y-m-d", $tomorrow);

So the first line gets todays date, then the next command gets today and converts it to a time string with the modifier +1 day. This can be week, month or day depending on the situation. Then we reformat the string as a date to output it. It’s really that simple.