如何在碳laravel中添加日期和另一个日期? [英] How can I add date with another date in carbon laravel?

查看:94
本文介绍了如何在碳laravel中添加日期和另一个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在laravel项目中,我想将日期时间增加到以前的日期时间.

In my laravel project, I want to increase the date time with the previous date time.

这是我的代码

$expire=$order[0]->expire_date;
$new=Carbon::now()->addMonths(6);

这两行的结果是

2018-01-28 21:23:56
2018-06-28 21:43:29

我想做的是将两个日期加起来.

What I want to do is sum the both dates.

$expire+$new 

我该如何实现?有什么想法或想法吗? 谢谢.

How can I achieve this? Any idea or thought? Thanks.

以更清晰的视图进行编辑

我想从now中找到到期日期的剩余天数,然后想将此剩余日期与新日期相加.希望它清除.

I want to find the remaining days of the expire date from now and then want to add this remaining date with the new date. Hope it clears.

推荐答案

如果您想将六个月的订单有效期添加进去,只需执行以下操作:

If you want to add six months to order expiration date, just do this:

$new = $order[0]->expire_date->addMonths(6);

这是可行的,因为$order[0]->expire_date是Carbon实例.

This will work since $order[0]->expire_date is a Carbon instance.

如果不是,请先解析:

$new = Carbon::parse($order[0]->expire_date)->addMonths(6);

这篇关于如何在碳laravel中添加日期和另一个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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