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

6ber6ou's avatar

Carbon diffForHumans Date to DateTime

Hi all.

I use this package to translate the Carbon dates in french : https://github.com/jenssegers/date I have this date :

Date::parse( $value )->diffForHumans();

Now I want to store the date in the created_at field of the DB. How can I modify the date to this format :

2016-03-04 09:31:13
0 likes
3 replies
ohffs's avatar
ohffs
Best Answer
Level 50

The docs on that page have an example :

Methods such as parse and createFromFormat also support "reverse translations". When calling these methods with translated input, it will try to translate it to English before passing it to DateTime:

$date = Date::createFromFormat('D d F Y', 'zaterdag 21 maart 2015');

Have you tried that?

6ber6ou's avatar

I haven't saw that.

$date = Date::createFromFormat('D d F Y', 'zaterdag 21 maart 2015');

the format returned is something like this

Date {#260
 +"date": "2015-08-27 11:48:30.000000"
  +"timezone_type": 3
 +"timezone": "UTC"
}

I try :

$date->date

but it's display an error

InvalidArgumentException in Carbon.php line 527:
Unknown getter 'date'
ohffs's avatar

If you're just wanting to store it in the DB you can just do $created_at = $date; and laravel should take care of the details :-)

Please or to participate in this conversation.