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

njhelloworld's avatar

categorize by date from timestamp

how to categorize data in the database through this date format , m-Y-d. that dates from database uses timestamp and I dont want to include time.I just wanted the date from timestamp

0 likes
6 replies
bobbybouwmann's avatar

Not really sure what your question is. Do you want to insert it with that date? Or do you want to fetch it with that date?

1 like
njhelloworld's avatar

I want to fetch the data with the date stored in my database.But this date uses timestamp.I want to categorize the data and I dont want to include the time only dates

Cronix's avatar

You can format it when you output it.

{{ $something->created_at->format('m-Y-d') }}

You can also format the date in the query itself.

App\User::selectRaw("DATE_FORMAT(created_at, '%m-%Y-%d') as created_at")->find(1);
njhelloworld's avatar

Here's the code in my controller if you can see, I'm trying to get the distinct Date but I cant I dont know how to display only the dates without repeating because of the Timestamp.

$events = DB::table('soildata') ->select('SoilDataID', 'Nitrogen', 'time_stamp') ->distinct() ->get(); return view('pages.filemanager',['events'=> $events ]);

this is also my code in my view @foreach ($events as $data) {{ date('d-m-Y',strtotime($data->time_stamp)) }} @endforeach

Above codes outputs all the date and not the distinct

Please or to participate in this conversation.