I am working on a Laravel project where I need to add a date field in the user profile section(a form). The date should:
- Be displayed in the format DD / MMM / YYYY (e.g., 25 / Jun / 2024).
- Allow users to edit/select the date.
- Send the date to the backend in a regular YYYY-MM-DD format when the form is submitted.
- Fetch the saved date from the backend and display it in the same DD / MMM / YYYY format when the page is visited.
I tried using <input type="date">
, but it displays the date as 25/06/2025
, which isn’t the desired format. I also tried following approach:
`
{!! Form::select(‘day’, range(1, 31), null, [‘placeholder’ => ‘Day’, ‘class’ => ‘form-control’]) !!}
{!! Form::select(‘month’, [’01’ => ‘Jan’, ’02’ => ‘Feb’, ’03’ => ‘Mar’, …, ’12’ => ‘Dec’], null, [‘placeholder’ => ‘Month’, ‘class’ => ‘form-control’]) !!}
{!! Form::select(‘year’, range(date(‘Y’), 1900), null, [‘placeholder’ => ‘Year’, ‘class’ => ‘form-control’]) !!}
`
The JavaScript code for aligning the number of days with the selected month and year, feels overly complex for such a simple requirement.
**Is there an easier way to:
**
Display the date in DD / MMM / YYYY format.
Allow users to edit/select the date.
Fetch and display the saved date(dd-mm-yyyy) in the correct format(dd-mmm-yyyy or 16-05-2025) when the page is visited.