How to convert a carbon into string, to take the date only?



PHP Snippet 1:

$collection_item->created_at->format('Y-m-d');

PHP Snippet 2:

$model_item->created_at->toDateString();

PHP Snippet 3:

// this includes created_at and updated_at by default so no need to add it 
protected $dates = ['approved', 'seen_at'];

PHP Snippet 4:

protected $casts = [
    'created_at' => 'date:Y-m-d',
    'updated_at' => 'datetime:Y-m-d H:00',
];

PHP Snippet 5:

 $carbon = Carbon::parse();

 echo (string)$carbon;
 // 2022-04-13 00:00:00

 $carbon->settings(['toStringFormat' => 'Y-m-d']);

 echo (string)$carbon;
 // 2022-04-13