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

GodziLaravel's avatar

Carbon : How to get only date without time ?

Hello ,

I try to get only the date without time :

$condition->value=Carbon::parse($seg["value"])->format('d-m-Y');

but the result is : 2020-03-17T11:07:00.000Z

How to keep only the Date ? 2020-03-17

0 likes
10 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102
$condition->value=Carbon::parse($seg["value"])->toDateString()
1 like
GodziLaravel's avatar

@sinnbeck thanks, but same problem :

the $condition->value type is string not date (It must be string , I cant change it )

Sinnbeck's avatar

sorry i dont understand? ->toDateString() return a string as the name implies

Carbon\Carbon::now()->toDateString(); //=> "2020-03-09"
GodziLaravel's avatar

@sinnbeck yes that's true but when I check the DB table I see : 2020-03-13T11:20:00.000Z I need just 2020-03-13

Sinnbeck's avatar

If it does not work, we will need more information. LIke what is $condition and how do you use it.

Sinnbeck's avatar

Is the column of type datetime? If so that is supposed to happen

Snapey's avatar

looks like an ISO8601 timestamp. You can just take the left most 10 characters?

Snapey's avatar

Thats just the current timestamp. What happened to the value in your database?

GodziLaravel's avatar

@snapey the value now is like : 2020-03-03 (string type and also the table column type is string -required to be string-) Carbon::parse($seg["value"])->format('Y-m-d');

Please or to participate in this conversation.