How can I create a carbon object from a given datetime structure?

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

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

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

Is it possible?

Or any other solution?

+5
source share
4 answers

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

+13
source

Based on a carbon document, you can convert a date string to a carbon object, for example:
1) Carbon::parse('1975-05-21 22:23:00.123456')
2) Carbon::create($year, $month, $day, $hour, $minute, $second, $tz);

+5
source

You can use parse() :

 Carbon::parse($dateString); 

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

 protected $dates = ['custom_date']; 
+4
source

You can check out this video. I think this is good for you.

https://laracasts.com/series/laravel-5-fundamentals/episodes/11

+1
source

Source: https://habr.com/ru/post/1261549/


All Articles