Reputation: 13
I have this timestamp created_at
public function getCreatedAtAttribute($value)
{
return Carbon::parse($value)->format('M d, Y h:i:s');
}
How can I format this like Oct 9, 2021 at 1:23 PM
with an at
string?
Upvotes: 0
Views: 684
Reputation: 628
return Carbon::parse($value)->format('M d, Y').' at '.Carbon::parse($value)->format('g:i A');
Upvotes: 0
Reputation: 12218
you can chain format as you need:
public function getCreatedAtAttribute($value)
{
return $value->format('M d, Y ').' at '.$value->format('h:i:s');
}
Upvotes: 3
Reputation: 2347
You can add the string by escaping the characters:
return Carbon::parse($value)->format('M d, Y \a\t H:i');
Upvotes: 4