-1

I got this date that I want to add a certain amount of days. I try to change this:

echo date('d-m-Y', strtotime($row_RSacessorios['Data_pedido']. ' + 10 days'));

Into this:

$numDays = $row_RSacessorios['Dias'];
echo date('d-m-Y', strtotime($row_RSacessorios['Data_pedido']. ' + ' . $numDays . ' days'));

My result is the same all the time "1-1-1970"

If I assume $numDays = 12 it gives me the correct date. mySQL date format is yyyy-mm-dd

CMartins
  • 3,247
  • 5
  • 38
  • 53
  • 1
    So what is `$row_RSacessorios['Data_pedido']`? You have that as the first part in strtotime and as the second part (in the second code part). `$numDays` should be some sort of number but you seem to imply it is a date. So you are adding two dates as far as I can tell. – brechmos Jun 23 '14 at 14:45
  • 1
    This is a duplicate of http://stackoverflow.com/questions/2332681/add-number-of-days-to-a-date – Bassem Jun 23 '14 at 14:46
  • Can you please output the $row_RSacessorios['Data_pedido'] data?, the problem should be around that. – Jorge Faianca Jun 23 '14 at 14:47
  • sorry $numDays = $row_RSacessorios['Dias']; – CMartins Jun 23 '14 at 14:47
  • Ok, but what are both of those variables? What are the actual values? – brechmos Jun 23 '14 at 14:48
  • $numDays int 12 and $row_RSacessorio['Data_pedido'] date 2013-04-10 – CMartins Jun 23 '14 at 14:50

2 Answers2

1

Small test.

$num = '10';

var_dump(date('d-m-Y', strtotime("+ $num days")));

$testDate = date('d-m-Y');

var_dump(date('d-m-Y', strtotime($testDate. " + $num days")));

After your comment Update,

$num = 12;
$testDate = '2013-04-10';
var_dump(date('d-m-Y', strtotime($testDate. " + $num days")));

You gave us this information, which works.

Please check your $row_RSacessorios['Data_pedido'] and $days variable.

Example:

http://codepad.viper-7.com/6OytfB

http://codepad.viper-7.com/Kgb7BX (after)

Jorge Faianca
  • 791
  • 5
  • 11
-2
$date = strtotime("+ ". $numDays . " day", $date);

could try this. i saw it on a different post

My guess is that strtotime has certain parameter order.. so if you put:

strtotime("+# days", $var);

it should work

DWolf
  • 703
  • 1
  • 7
  • 20