Reputation: 746
I have a List of records in my database and I am presenting problems using php carbon
First, I try to perform the cast of a date, in my database I have 2019-11-13 22:55:00
and when I do the cast Carbon::parse($fieldDateTime)->format('d m Y H: m: s')
I get as a result 13 11 2019 21:11:00
, Why is this happening ?
I have a list of records and I want to filter them so they have an approximate date of 3 hours, to alert the user that in 3 hours he has to do an action.
$filtered = $collection->filter(function($cita){
$diffMinutes = Carbon::parse($fieldDateTime)->diffInMinutes(Carbon::now()->subMinutes(180));
return Carbon::parse($fieldDateTime)->isToday() &&
($diffMinutes==0) ;
});
How can i solve this problem?
Upvotes: 0
Views: 75
Reputation: 782
You need to get your date value from the database and convert it into the carbon instance. Then, you can get the subtraction function from carbon.
$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
}
Upvotes: 2