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

6ber6ou's avatar

How to store date in database

Hi all.

I have an input text where the user enter a date in this format : dd-mm-yyyy I have a migration with this field :

$table->date( 'end_guarantie' );

How can I transfrom the user input to store it in the DB ?

0 likes
1 reply
CrucialDev's avatar

I have a helper function that creates Carbon instance and then I pass that when saving my model.

function createDate($date)
{
    $edate = Carbon::createFromFormat('m/d/Y g:i A', $date);
    return $edate;
}

You get $date from the request and save $edate to your model. You will need to update the format in the createFromFormat 1st argument to what you are using.

Please or to participate in this conversation.