gpt4 book ai didi

php - 如何使用数组中的 date_diff() 查找两个日期之间的差异

转载 作者:行者123 更新时间:2023-12-03 20:21:20 24 4
gpt4 key购买 nike

<分区>

我需要找出数组中两个日期之间的差异。这是数组:

$lists[] = date('Y-m-d', strtotime($user->created_at));

echo $lists[1]; 的示例输出是 2017-08-01

我试过了

$difftime = $lists[1]->diff($lists[0]);
echo $difftime->format('d');

echo $lists[1]->diff($lists[0]);

都给我错误:

Call to a member function diff() on string

我也尝试过 echo date_diff($lists[1], $lists[0]);

报错

date_diff() expects parameter 1 to be DateTimeInterface, string given

我知道这里有很多关于同一问题的问题,但我找不到适合我的解决方案。所以请帮助我。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com