Ziaur Rahman Ziaur Rahman - 8 months ago 77
PHP Question

Make a Carbon object out of request input

How can I make use of the Carbon functionality with input from the request?

I am using a variable

$pre_Date
which comes from my request:

$pre_Date = Input::get('Date');


Now I want to add a month with the variable
$pre_Date
. I can use it with current date using
Carbon::now()->addMonth(1)
. How can i use addMonth() function for a variable $pre_Date which is not current date.

The format of $pre_Date variable is
'Y-m-d'

Answer Source

You first create a Carbon object from your string.

$date = Carbon::createFromFormat('Y-m-d', $Date);
$date->addMonth();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download