Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Friedrich's avatar

I have a LARAVEL problem

I want to compute the First Date range and the Last Date range of one user TIME IN and TIME OUT hours my problem is logic about CARBON from createFromFormat it always thrown an error about data missing can someone have the logic of this problem that would help me.

 $day=Tms::whereBetween('day', [$request->first, $request->last])->get();
        $users=Tms::where('users_id', $request->user)->value('users_id');
       	$user_time_in=Tms::where('users_id',$request->user)->whereBetween('day', [$request->first, $request->last])->value('time_in');
        $user_time_out=Tms::where('users_id',$request->user)->whereBetween('day', [$request->first, $request->last])->value('time_out');
         $timeIn=Carbon::createFromFormat('g:i A', $user_time_in);
         $timeOut=Carbon::createFromFormat('g:i A', $user_time_out);
         $total_hours=$timeIn->diffInHours($timeOut);
         $total_minutes=$timeIn->diffInMinutes($timeOut);
         $total=$total_minutes/60;
        return view('home.admin.tms.calculated_hours')->with(['day'=>$day, 'users'=>$users]);

In summary of this problem I want to compute the total hours of between dates filtered of one user. Please Help badly need

0 likes
15 replies
tykus's avatar

No way to really know without understanding the nature of the data. A data missing type Carbon error message usually means the format if the data does not match the format.

Other than that, I am not sure what your queries are intended to achieve, e.g. what is this intended to do?

$users=Tms::where('users_id', $request->user)->value('users_id');
Friedrich's avatar

@tykus to get the users username because my one to many eloquent does not work

Friedrich's avatar

@tykus I have

//in my data collection
users Id: name="user"
from: name="first"
to: name="last"

//i want to compute the total hours of requested user
users id: 4
from (2022/8/12) = 8:09AM
to (2022/12/25) = 9:08PM
total hours:45 hours
//something like this
tykus's avatar

@Friedrich that query does not get a value from a username column ¯\_(ツ)_/¯ `

Anyway, what does the data in the time_in and time_out columns look like?

tykus's avatar

@Friedrich I meant the fact that 9:30 is represented as 8:90

Anyway the full error message????

tykus's avatar

@Friedrich I meant stacktrace etc. it is really difficult to help if you are sparse with information

Friedrich's avatar

@tykus

$day=Tms::where('users_id',$request->user)->whereBetween('day', [$request->first, $request->last])->get();
        foreach($day as $hour){
$timeIn=Carbon::createFromFormat('g:i A', $day->time_in);
$timeOut=Carbon::createFromFormat('g:i A', $day->time_out);
$total_minutes=$timeIn->diffInMinutes($timeOut);
            $total=$total_minutes/60;
            dd($total);
        }

i have new idea logic

tykus's avatar

@Friedrich how can you possibly expect help when you won't provide the information necessary to help you?

why will you not post the full error message and stacktrace?

Please or to participate in this conversation.