kate_hudson kate_hudson - 1 year ago 65
PHP Question

Add 1 month to part string date

wasnt sure how to best describe this. I make an API call and one of the elements I get back is like the following

0 => array:3 [▼
"customId" => "12345"
"customName" => "Month"
"customValue" => "June 16"

As you can see the customValue is June 16, meaning June 2016. Is there any way I can add 1 month onto this, so to make it July 16? I know I could simply replace Jun with July using something like str_replace, but I do not want to change the expression month on month. What I am really looking for is to have the system understand that this is Jun 16 and 1 month needs adding onto it.

Would this be possible?


Ben Ben
Answer Source

To change the value of $monthAndDay:

$monthAndDay = "June 16";
$monthAndDay = date("F j", strtotime($monthAndDay." + 1 month"));

echo $monthAndDay; //outputs July 16

Within an array:

$arr = [
    "customId" => "12345"
    "customName" => "Month"
    "customValue" => "June 16"

$arr["customValue"] = date("F j", strtotime($arr["customValue"]." + 1 month"));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download