问题解析与 Carbon 的日期并获得差异 PHP ,Carbon
Problem parsar a date with Carbon and get differences PHP , Carbon
我的数据库中有一个记录列表,我正在使用 php carbon
提出问题
首先,我尝试执行日期转换,在我的数据库中我有 2019-11-13 22:55:00
,当我执行转换时 Carbon::parse($fieldDateTime)->format('d m Y H: m: s')
结果是 13 11 2019 21:11:00
,为什么这是在发生吗?
我有一个记录列表,我想过滤它们,使它们具有大约 3 小时的日期,以提醒用户他必须在 3 小时内执行操作。
$filtered = $collection->filter(function($cita){
$diffMinutes = Carbon::parse($fieldDateTime)->diffInMinutes(Carbon::now()->subMinutes(180));
return Carbon::parse($fieldDateTime)->isToday() &&
($diffMinutes==0) ;
});
我该如何解决这个问题?
您需要从数据库中获取日期值并将其转换为碳实例。然后,你可以从碳中得到减法函数。
$time = \Carbon\Carbon::parse($YourTimeFromDataBase);
$minutes = Carbon::now()->diffInMinutes($time);
//it will give you in minute. then you can easily check if the time exceed 3*60 mins ort not.
if($minutes>180){
//do somthing
}else{
//do something
}
我的数据库中有一个记录列表,我正在使用 php carbon
提出问题首先,我尝试执行日期转换,在我的数据库中我有 2019-11-13 22:55:00
,当我执行转换时 Carbon::parse($fieldDateTime)->format('d m Y H: m: s')
结果是 13 11 2019 21:11:00
,为什么这是在发生吗?
我有一个记录列表,我想过滤它们,使它们具有大约 3 小时的日期,以提醒用户他必须在 3 小时内执行操作。
$filtered = $collection->filter(function($cita){
$diffMinutes = Carbon::parse($fieldDateTime)->diffInMinutes(Carbon::now()->subMinutes(180));
return Carbon::parse($fieldDateTime)->isToday() &&
($diffMinutes==0) ;
});
我该如何解决这个问题?
您需要从数据库中获取日期值并将其转换为碳实例。然后,你可以从碳中得到减法函数。
$time = \Carbon\Carbon::parse($YourTimeFromDataBase);
$minutes = Carbon::now()->diffInMinutes($time);
//it will give you in minute. then you can easily check if the time exceed 3*60 mins ort not.
if($minutes>180){
//do somthing
}else{
//do something
}