【问题标题】:Difference between two dates in LaravelLaravel中两个日期之间的差异
【发布时间】:2020-10-19 01:55:32
【问题描述】:

我对两天之间的差异有疑问。

如何获得天数?

这是我的代码,

$start = date('Y-m-d', strtotime("+1 day"));
$end = date('Y-m-d', strtotime("+7 day"));

【问题讨论】:

标签: laravel date


【解决方案1】:

我使用纯 PHP:

$start = date('Y-m-d', strtotime("+1 day"));
$end = date('Y-m-d', strtotime("+7 day"));
$diff = abs(strtotime($start) - strtotime($end));
$days = floor($diff/60/60/24);
$total = sprintf("%d days\n", $days);
return $total; // 6 days

【讨论】:

    猜你喜欢
    • 2020-09-18
    • 2011-10-29
    • 1970-01-01
    • 2013-10-02
    • 2012-01-15
    • 2016-12-30
    • 2011-06-13
    • 2021-10-06
    • 1970-01-01
    相关资源
    最近更新 更多