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

Jam0r's avatar
Level 8

Adding current time to date via Carbon

I watched a video on here a while ago where Jeffrey did this but cannot find it.

I have a timestamp field but I only want the user to select the date and store an item.

Trouble is a user may store 2 or 3 items on the same day so I want to automatically add the time as I want to be able to sort them by most recent.

There was a simple way of doing this via Carbon, anyone know what it is?

0 likes
1 reply
ejdelmonico's avatar

Laravel will pull out a date as a Carbon instance through Eloquent. If you want to change a raw timestamp to get just the time, then

$dt = Carbon::create(1975, 12, 25, 14, 15, 16);  // or Carbon::now()

$dt->toTimeString();                          // 14:15:16

Please or to participate in this conversation.