Given 2008-01-31 as the current date and the value of “$days_before” is 2, the code will echo 2008-01-29. The date 2 days before the current date.
$days_before = 2; $current_date = date('Y-m-d'); $str = strtotime($current_date)-(86400*$days_before); //1 day has 86400 echo date('Y-m-d',$str); |