Search code examples
phplaravellaravel-5.3php-carbon

How to add 1 hour to date Carbon?


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();

Solution

  • 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();