-1

I have to compute a specific date considering the number of days I want to substract.

My code looks roughly like this:

$datac = date("Y-m-d");
$data = strtotime("-1 day" ,$datac);

But the output is: -84384 I don't understand what I do wrong. It should work something like date -1 and show the date from yesterday. Thank you!

Vlad Eugen Nitu
  • 195
  • 2
  • 15
  • 2
    `$datac`needs to be a timestamp, not a formatted date.. You can find more information about `strtotime()` in the [manual](http://php.net/manual/en/function.strtotime.php) – Naruto Jan 12 '16 at 14:30
  • Because the second argument to [strtotime()](http://php.net/manual/en/function.strtotime.php) should be a unix timestamp, not a formatted date string – Mark Baker Jan 12 '16 at 14:30

2 Answers2

0
$datac = new DateTime();
$datac->modify('-1 day');
$data = $datac->format('Y-m-d');
Gilberto Ramos
  • 105
  • 1
  • 9
0
$datac = date("Y-m-d");
$data = date("Y-m-d", strtotime('-1 day' . $datac));
Sergynyo
  • 11
  • 3