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

blackshtef's avatar

Date selector for Laravel?

So, I'm using a standard HTML5 datepicker like so:

<div class="form-group">
                    <x-input data-provide="datepicker" id="event_date" type="date" name="event_date" value="<?php echo date('Y-m-d'); ?>" />
                </div>

I want the date to be displayed in a DD-MM-YYYY format, but saved into the database as YYYY-MM-DD. Somehow, whatever I put in the echo date() - it doesn't matter - here is Y-m-d, but when I render the form, I will get 12/27/2022 (and I want it to be 27-12-2022). It saves it correctly in the database, but I don't have any more ideas on how to solve this. As much as I could google it out, it seems that standard HTML5 datepicker just can't be customized in that way - or it depends on the setup of local computer?

Is there an easy way, or a Laravel library or something I could use?

0 likes
7 replies
ganeshghalame's avatar

Can you try data-date-format="dd-mm-yyyy" as below

<div class="form-group">
    <x-input data-provide="datepicker" data-date-format="dd-mm-yyyy" id="event_date" type="date" name="event_date" value="<?php echo date('Y-m-d'); ?>" />
</div>

This will display the date in the dd-mm-yyyy format in the datepicke

Sinnbeck's avatar

If you want full control over the input, I highly recommend using a javascript date picker (or hide the input field and show your own values). The browser date picker is great but its limited in how it is presented

Please or to participate in this conversation.