Home > Back-end >  How to format timestamp in laravel?
How to format timestamp in laravel?

Time:11-10

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?

CodePudding user response:

You can add the string by escaping the characters:

return Carbon::parse($value)->format('M d, Y \a\t H:i');

CodePudding user response:

you can chain format as you need:

public function getCreatedAtAttribute($value)
{
  
     return $value->format('M d, Y ').' at '.$value->format('h:i:s');
}

CodePudding user response:

   return Carbon::parse($value)->format('M d, Y').' at '.Carbon::parse($value)->format('g:i A');  
  • Related