@Uhanalainen parse never sets time part, unless you provide it. parseFromFormat always sets it, just like you said.
Carbon::parse not working as expected
I'm watching the Laravel 5 fundamentals -series, and it's been great so far, but I'm stuck on lesson 11. Jeffrey uses Carbon::parse($date) to get a carbon instance of the date given in the form, and in the video, it works like so:
If the day is the current day, the time will be the current time. Otherwise, if the given date is in the future, the publication date will be the given date, BUT the time will be 00:00:00.
I've been toying around this thing for hours, but I can't seem to grasp why it's not working, and judging by the comments, I'm not alone. I've been trying to move on, even, but this bugs the heck out of me, and I'm reluctant to move on for fear of other, more serious complications rising up in front of me.
I actually sort of got it working with Carbon::createFromFormat('Y-m-d', $date) but with that, the time will always be current time even if the date is in the future, which was the reason Jeffrey changed it in the video to Carbon::parse.
I'm thinking of making a subscription (love the quality vids here!) but I need to know that I can get help if I get stuck with them for whatever reason, so any help in this issue would be great.
Thanks in advance.
@Uhanalainen I'm not watching the video and not referring to it, but I suppose you don't know how parse can be used.
You pass any string representation of a date/timestamp to the method:
[1] > Carbon::parse('-1 day');
// object(Carbon\Carbon)(
// 'date' => '2015-02-26 11:18:58',
// 'timezone_type' => 3,
// 'timezone' => 'Europe/Warsaw'
// )
[2] > Carbon::parse('tomorrow');
// object(Carbon\Carbon)(
// 'date' => '2015-02-28 00:00:00',
// 'timezone_type' => 3,
// 'timezone' => 'Europe/Warsaw'
// )
[3] > Carbon::parse('1 year 1 month 22 day 5 hour');
// object(Carbon\Carbon)(
// 'date' => '2016-04-18 16:19:17',
// 'timezone_type' => 3,
// 'timezone' => 'Europe/Warsaw'
// )
[4] > Carbon::parse('-1 year 1 month 22 day 5 hour');
// object(Carbon\Carbon)(
// 'date' => '2014-04-18 16:19:23',
// 'timezone_type' => 3,
// 'timezone' => 'Europe/Warsaw'
// )
[5] > Carbon::parse('2015-02-20 12:55:11');
// object(Carbon\Carbon)(
// 'date' => '2015-02-20 12:55:11',
// 'timezone_type' => 3,
// 'timezone' => 'Europe/Warsaw'
// )
[6] > Carbon::parse('2015-02-20');
// object(Carbon\Carbon)(
// 'date' => '2015-02-20 00:00:00',
// 'timezone_type' => 3,
// 'timezone' => 'Europe/Warsaw'
// )
Please or to participate in this conversation.