douhanzhuo6905 2017-05-19 20:29 采纳率: 100%
浏览 289
已采纳

Laravel Carbon错误与年份之间的差异

Good afternoon... I try to make the difference in years between the current date and a date in the database like this:

$final = '2016-05-10'; //date database
$hoy = \Carbon\Carbon::now(); //today
$fecha_ingreso = \Carbon\Carbon::createFromFormat('Y-m-d', $final);

$diff = $hoy->diffInYears($fecha_ingreso); //diff

But when doing a var_dump() of $fecha_ingreso it shows me the following:

object(Carbon\Carbon)#259 (3) { ["date"]=> string(26) "2155-05-10 22:27:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }

The day and the month are ok but the year is not, why can this error be ?? Thank you very much for the help.

  • 写回答

1条回答 默认 最新

  • dsn5510 2017-05-20 05:37
    关注

    I assume you want the difference in number of years, try this.

    $dbDate = \Carbon\Carbon::parse('2016-05-10');
    $diffYears = \Carbon\Carbon::now()->diffInYears($dbDate);
    
    // $diffYears is 1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号