How to add 1 hour to date Carbon?

Goga picture Goga · Nov 24, 2016 · Viewed 44.3k times · Source

I have datetime "2016-11-24 11:59:56". How can I add one hour to this date and compare it with current datetime?

I tried:

$date = "2016-11-24 11:59:56";
$date->addHour();

Answer

Alexey Mezenin picture Alexey Mezenin · Nov 24, 2016

Try to parse() it first:

$date = Carbon::parse('2016-11-24 11:59:56')->addHour();

Better way is to add datetime column to a dates variable:

protected $dates = ['datetime_column'];

Then you can just do this:

$date = $model->datetime_column->addHour();