0

I have an error message but I don't understand the problem ?

"Unexpected data found. Unexpected data found. Data missing."

Visibly, my problem is here ???

"d-m-Y HH:ss" " 18:00"

$start_time = Carbon::createFromFormat('d-m-Y HH:ss', $request->date_revision_start . ' ' . $request->hour_start);
$stop_time = Carbon::createFromFormat('d-m-Y HH:ss', $request->date_revision_start . ' ' . $request->hour_end);

Here my code:

public function store(Request $request)
 {
     $request->validate([
       'date_seance' => 'required',
       'hour_start' => 'required',
       'hour_end' => 'required',
       'fk_motorbike' => 'required',
       'fk_former' => 'required',
       'fk_student' => 'required',
       'fk_typeseance' => 'required'


]);


$start_time = Carbon::createFromFormat('d-m-Y HH:ss', $request->date_revision_start . ' ' . $request->hour_start);
$stop_time = Carbon::createFromFormat('d-m-Y HH:ss', $request->date_revision_start . ' ' . $request->hour_end);

1 Answer 1

2

In createFromFormat method remove double letters.

'd-m-Y H:s'

I tested like this and it works

$date_revision_start = '20-05-2019';
$hour_start = '17:00';
$hour_end = '18:00';

$start_time = Carbon::createFromFormat('d-m-Y H:s', $date_revision_start . ' ' . $hour_start);
$stop_time = Carbon::createFromFormat('d-m-Y H:s', $date_revision_start . ' ' . $hour_end);

dd($start_time, $stop_time);

Output

  1. date: 2019-05-20 17:00:00.0 UTC (+00:00)
  2. date: 2019-05-20 18:00:00.0 UTC (+00:00)

Explanation

You were formatting time incorrectly

dd(Carbon::parse($date_revision_start)->format('d-m-Y HH:ss'));

gives

"20-05-2019 1717:0000"
Sign up to request clarification or add additional context in comments.

2 Comments

As a reference, date() documentation contains a table with all the possible formatters each with a meaningful description and example
@Dino Numić: Thank you , it's OK now... :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.