Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My question possibly may be a duplicate from this question:

PHP Fatal error: Call to a member function format() on boolean

But I'm sure that my question is not a duplicate.

I have a problem with try to save records in datetime format.

The error is the following:

Symfony Component Debug Exception

FatalThrowableError (E_ERROR)

Call to a member function format() on boolean

1° record

Columns date_start and date_end respectively

court_id = 1 - NAME= TENNIS

2018-10-05 10:00:00 - 2018-10-05 11:00:00 works perfectly. It's save without problems

Then I try to save another record in my table.

The same columns respectively.

2° Record

court_id = 1 - NAME = TENNIS

2018-10-05 12:00:00 - 2018-10-05 13:00:00 not work, but it's work if the day is different for example 2018-10-06.

The dates are similar and court_id are the same, the only difference between the record 1 and 2 are the hours.

This is my function store()

public function store(Request $request){


    $hours = new HoursNew();

    try {


        $hours->id = $request->id;

        $date = DateTime::createFromFormat('Y-m-dTh:i', $request->date_start);
        $date2 = DateTime::createFromFormat('Y-m-dTh:i', $request->date_end);


        //THIS LINE SHOW ME AS AN ERROR
        $hours->date_start = $date->format('Y-m-d H:i:s');


        $hours->date_end = $date2->format('Y-m-d H:i:s');


        $hours->estate_hour_id = $request->estate_hour_id;
        $hours->court_id = $request->court_id;
        $hours->save();

    } catch (IlluminateDatabaseQueryException $e) {

         Session::flash('error', 'Whoops! We have some problems');

         return redirect()->route('ListHours.store');

    }
        Session::flash('message', "It's OK");
        return redirect()->route('ListHours.store');
}

Why I get this error, when I try to save the same dates for the same courts (court_id) but differents hours.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
613 views
Welcome To Ask or Share your Answers For Others

1 Answer

http://php.net/manual/en/datetime.createfromformat.php

DateTime::createFromFormat() returns false on failure. Since the hour goes from <= 12 to 13 in your example, that indicates to me that the "h" should be capitalized.

$date = DateTime::createFromFormat('Y-m-dTH:i', $request->date_start);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...