Somar int with date - PHP

0

I have the function below, which does the sum of date, with the value +2 days fixed:

echo date('d/m/Y', strtotime("+2 days",strtotime($ultima_data)));

It correctly sums up with the $ last_data value, but somehow needs to change the +2 days to a value that is in another variable, but so far I did not make it. I tried the following ways, without success:

echo date('d/m/Y', strtotime($dias_frequencia,strtotime($ultima_data)));

echo date('d/m/Y', strtotime("+'$ultima_frequencia'days",strtotime($ultima_data)));

In both cases there was no error, but returned values of 1969 ... Any ideas?

    
asked by anonymous 31.03.2016 / 16:38

2 answers

1

I know that until now the question has probably been resolved, I commented on the lack of space:

  

Missing a space here: "+'$ultima_frequencia'days" would not it be "+'$ultima_frequencia' days" ?

But I forgot to mention the unnecessary apostrophes too, that is to say:

 echo date('d/m/Y', strtotime("+'10' days"));

It will return 1969 or 1970, something like it will be displayed:

  

01/01/1970

Now doing so works:

 echo date('d/m/Y', strtotime("+10 days"));

In the case today being 08/24/2018 this was displayed to me (this month ends on the 31st):

  

03/09/2018

In other words, the problem is not concatenating, in fact with double quotation marks it is not always necessary to concatenate and it does not cause readability problem to use variables within these quotes, you can even make it more visible using something like:

 echo "Olá $nome, você recebeu {$mail->mailbox[0]->messages}";

What from my point of view is as readable as concatenating:

 echo "Olá " . $nome . ", você recebeu " . $mail->mailbox[0]->messages;
    
24.08.2018 / 16:10
0

do this:

echo date('d/m/Y', strtotime("+" . $ultima_frequencia  . " days",strtotime($ultima_data)));

Concatenating, your code becomes more readable.

    
31.03.2016 / 17:38