How to add 2 months to a date in PHP inside HTML codes?

I am new to PHP and want to add 2 months to a specific date in the html code. How can I do it? I ask you to consult

Here is the code I'm using:

private function inputExpiryDate() { $value = $this->expiryDate; $html = ""; $html .= '<label for="expirydate">Expiry Date:</label>'; $html .= '<input type="text" readonly name="expirydate" id="expirydate" value="'.$value.'">'; $html .= '<input type="button" id="expirydatebutton" onclick="getExpiryDate()">' . PHP_EOL; return $html; } 

The question is, how can I add this

 $date = strtotime(date("Ymd", strtotime($date)) . " +2 month"); ?? 

Any help really appreciated.

+4
source share
3 answers

You do not need to decompose the value of $date to use it when the relative date changes. This should work as expected:

 $date = date('Ym-d', strtotime("$date +1 month")); 
+6
source

After

 $date = strtotime(date("Ymd", strtotime($date)) . " +1 month"); 

Add row

 echo date("Ymd", $date); 

As the first sentence will return you a Unix timestamp, so you will need to convert it to a readable format

+3
source

you just need to add date('Ymd) like this date('Ym-d',strtotime(date("Ymd", strtotime($date)) . " +1 month"))

+1
source

Source: https://habr.com/ru/post/1438553/


All Articles