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

muragijimana's avatar

how to format date unix way?

I have a date like this Wed Jun 29 2016 00:00:00 GMT+0200 And I am using a mutator like the following

public function setpurchasingDateAttribute($value)
    {
            $this->attributes['purchasing_date'] = Carbon::createFromFormat('Y-m-d H:i:s',$value);
 }

I get this errorUnexpected data found. Meaning that may be I am formatting badly. Can anyone help me out?

0 likes
1 reply
tomopongrac's avatar

Try this

public function setpurchasingDateAttribute($value)
    {
            $this->attributes['purchasing_date'] = Carbon::createFromFormat('D M Y H:i:s eO',$value);
 }

Please or to participate in this conversation.