Date format in select box Im sending a collection of dates to a select field in a laravel form. These collections are in $statements.
I want the format of the date to be dd/mm/yyyy.
The select box gives me yyyy-mm-dd.
{{ Form::label('statement', 'Statement: ')}}
{{ Form::select('statement', $statements, array('class' => 'form-control input-lg')) }}
How can I format the date the way I want it?
I think you might be digging a bit deep into this one.
Just format the date.
$date = date( j/m/Y , strtotime( $request->date ) )
Or a more Laravely way might be to use Carbon
Use this to create a Carbon instance from the passed data.
Carbon::createFromFormat('Y-m-d H', '1975-05-21 22')
And then maybe if you're storing this back to a database you could
Carbon::createFromFormat('Y-m-d H', '1975-05-21 22')->toDateTimeString();
as @lyleyboy suggest you are better off formatting the date before you send it through as your select will only display options and is not of type="date" input. If the input you were sending it too where a date input you could set this in your HTML form.
Please sign in or create an account to participate in this conversation.