0

How can i put a variable month in date function ?

$nbrmonth = 6;

$onemonth = date('Y-m-d H:i:s',strtotime(date("Y-m-d H:i:s", mktime()) . " + 1 month")); //work
$variabledate = date('Y-m-d H:i:s',strtotime(date("Y-m-d H:i:s", mktime()) . " + '.$nbrmonth.' month")); // not working 
psppro26
  • 25
  • 5
  • 1
    Try `$variabledate = date('Y-m-d H:i:s',strtotime(date("Y-m-d H:i:s", mktime()) . ' + ' . $nbrmonth . ' month'));` – Goma Nov 28 '17 at 14:57
  • Possible duplicate of [PHP - concatenate or directly insert variables in string](https://stackoverflow.com/questions/5605965/php-concatenate-or-directly-insert-variables-in-string) – Tom Udding Nov 28 '17 at 15:26

2 Answers2

0
$variabledate = date('Y-m-d H:i:s',strtotime(date("Y-m-d H:i:s", mktime()) . " + ".$nbrmonth." month")); //  working

Try out this.

This is the output:

2018-05-28 16:00:11
pr1nc3
  • 8,108
  • 3
  • 23
  • 36
0

Try this:

$variabledate = date('Y-m-d H:i:s',strtotime(date("Y-m-d H:i:s", mktime()) .' + ' 
 .$nbrmonth .' month')); 
dns_nx
  • 3,651
  • 4
  • 37
  • 66