首页 > 解决方案 > Carbon::today()->toDateString() 不等于今天的日期

问题描述

对于我的代码:

$today = Carbon::now()->toDateString();
$compare = Carbon::today()->toDateString() == '2020-12-03' ? 'yes' : 'no';
Log::debug('today '.$today);
Log::debug('compare '.$compare);

它返回给我:

2020-12-03
no

任何人都可以帮助向我解释为什么它返回“否”而不是“是”。

标签: php-carbon

解决方案


toDateString() 函数返回字符串并且您的日期不是字符串格式。

字符串比较示例

另一个比较的例子


推荐阅读