使用碳获取两个日期之间的日差 [英] get day difference between two date using carbon

查看:42
本文介绍了使用碳获取两个日期之间的日差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用laravel和碳纤维包装.我有两个约会.现在,我要获得与给定日期的日期差.

I am using laravel and carbon package.I have two date. Now I want to get date difference from my given date.

$start_Date='2016-06-02 18:00:13';
$end_Date='2016-06-06 18:00:13';
$start = Carbon::parse($start_Date);
$end = Carbon::parse($end_Date);
$now = Carbon::now();
$length = $start->diffInDays($now);
$lengthFromEnd = $end->diffInDays($now);

如果 now()== 2016-06-07 然后

$ length 将是 5天

$ lengthFromEnd 将为 -1天.

但是我的代码返回了异常结果

but my code return abnormal result

推荐答案

您也可以尝试这种方式.

you can also try this way.

$difference = $start_date->diff($end_date)->days;

这篇关于使用碳获取两个日期之间的日差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆