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

irwan_up's avatar

[Carbon] how to get a date stored in mysql can be accessed using diffForHumans()

I have a date called 'deadline' which is stored in mysql as timestamp, but when i tried to output it on a view : {{ @order->deadline->diffForHumans() }} It gets error, which said it is not an object. But for {{ @order->created_at->diffForHumans() }} and {{ @order->updated_at->diffForHumans() }} both works perfectly. Hope anyone can help me, thanks a lot...

0 likes
5 replies
thomaskim's avatar

created_at and updated_at are Carbon instances by default. If you want other dates, timestamps, etc. to be Carbon instances, then you need to let Laravel know by adding them to the $dates property in your Model.

protected $dates = ['deadline'];
2 likes
irwan_up's avatar
irwan_up
OP
Best Answer
Level 2

thanks for the answers guys, i found one that works : {{ Carbon::createFromTimestamp(strtotime(@order->deadline))->diffForHumans() }}

thomaskim's avatar

Why would you manually create the Carbon instance manually when you could simply set the property and let it be automatically handled?

If you want to manually create it, instead of using strtotime, it would also be simpler to just use the static parse method:

Carbon::parse($order->deadline)->diffForHumans().

irwan_up's avatar

i didn't know that, i'll try it later. thanks thomaskim

Please or to participate in this conversation.