Here is different way to get the date of a selected day ago in PHP. The ways are as bellow -
Way - 1:
strtotime() will do the trick. Convert your previous date to a Unix timestamp using mktime(), then use it like this:
$from_unix_time = mktime(0, 0, 0, $month, $day, $year);
$day_before = strtotime("yesterday", $from_unix_time);
$formatted = date('Y-m-d', $day_before);
Way - 2:
You can also use strtotime function using words like this:
$date = '2012-11-08'; $day_before = date( 'Y-m-d', strtotime( $date . ' -1 day' ) );
The output of $day_before:
2012-11-07
Way - 3:
You can rely on mktime()’s ability to work with “incorrect” values. Let’s assume $year, $month and $day are current day.
$yesterday = mktime (0, 0, 0, $month, $day - 1, $year);
echo date ('Y-m-d', $yesterday);
Don’t worry, it will just do the right thing: try yourself with different values.