Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could i create carbon object from given datetime structure?

I use laravel, i need to create carbon object from the timestamp that i received.

TimeStamp : 'yy-mm-dd HH:mm'

ex. '2016-12-20 10:26'

Is this possible ?

Or Any other solution ?

like image 665
Shankar Thiyagaraajan Avatar asked Dec 20 '16 06:12

Shankar Thiyagaraajan


2 Answers

Use Carbon::parse('2016-12-20 10:26');, it will return a Carbon object.

like image 61
SteD Avatar answered Oct 24 '22 20:10

SteD


You can use parse():

Carbon::parse($dateString);

Or you can use $dates property to create Carbon instance automatically for the column:

protected $dates = ['custom_date'];
like image 43
Alexey Mezenin Avatar answered Oct 24 '22 21:10

Alexey Mezenin