Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gabonator's avatar

Save date and time through two inputs

HI,

I have table

$table->dateTime('dateStart');
}

and I need save date and Time comes from two inputs to one column.

    <input type="date" name="dateStart" placeholder="Krátky popis" class="form-control input-sm" required>

   <input type="time" name="dateStart" placeholder="Krátky popis" class="form-control input-sm" required>


I am tray something like this.

        $event->update([
            'dateStart'  => $request->input('timeStart')->format('H:i:s')
        ]);

but not eorking.

Use input type="datetime-local" only in the extreme case.

Its possible to do?

Thx a lot.

Gabriel
0 likes
4 replies
Snapey's avatar

You cannot have two form inputs with the same name;

    <input type="date" name="dateStart" placeholder="Krátky popis" class="form-control input-sm" required>

   <input type="time" name="dateStart" placeholder="Krátky popis" class="form-control input-sm" required>

The second will override the first.

If you need separate fields, call them something different then concatenate them together and pass to the Carbon parse function to create a carbon object.

Also note that type="date" is not supported in Firefox, or Internet Explorer 11 and earlier versions.

Gabonator's avatar

... call them something different then concatenate them together and pass to the Carbon parse function to create a carbon object.

How?

Snapey's avatar
Snapey
Best Answer
Level 122
    <input type="date" name="dateStart" placeholder="Krátky popis" class="form-control input-sm" required>

   <input type="time" name="timeStart" placeholder="Krátky popis" class="form-control input-sm" required>

controller

    $event->update([
        'dateStart'  => $request->dateStart . ' ' . $request->timeStart .':00';
    ]);

Please or to participate in this conversation.