How to compare two Carbon Timestamps?

后端 未结 4 648
你的背包
你的背包 2020-11-29 17:52

I have two timestamps, edited_at which I created and created_at (Laravel\'s)... In database, both have type timestamp and default value 0000-00-00 00:00:00... But

4条回答
  •  粉色の甜心
    2020-11-29 18:33

    First, convert the timestamp using the built-in eloquent functionality, as described in this answer.

    Then you can just use Carbon's min() or max() function for comparison. For example:

    $dt1 = Carbon::create(2012, 1, 1, 0, 0, 0); $dt2 = Carbon::create(2014, 1, 30, 0, 0, 0); echo $dt1->min($dt2);

    This will echo the lesser of the two dates, which in this case is $dt1.

    See http://carbon.nesbot.com/docs/

提交回复
热议问题