Laravel + Carbon + SQL time formatting problem

Viewed 28

Can someone please assist me with the following problem. I am using Carbon to get the current time. Once I got the time and send it to my (myphpadmin) database it displays the whole date and time and not just the time. Here are all the code being used.

Laravel Code:

            $date = Carbon::parse(now())->timezone('GMT+2');
            $time = $date->toTimeString();
            $UserRequest->finished_at = $time;

SQL Database layout and format:

enter image description here

Display: (Incorrect)

enter image description here

I have literally tried all the custom formatting from Carbon docs nothing sends over just the time.

I need this format -> 12:09 pm

Table Structure:

enter image description here

1 Answers

The problem more complicated than you describe. First looks as finished_at is datetime field, so you can not store only date in this field. Sure, you can change the column format to time and store only time part. But this approach can cause problem with overdate date (started_at may be previous day or early).

So I think you need not change your storing flow, but you can change representation flow by using appropriate format

Related