Default date format
In v3 I was able to set the default date format in the boot section of the AppServiceProvider using the code below, this does not seem to work in v4, any idea on how to achieve this?
DateTimePicker::configureUsing(fn () => DateTimePicker::$defaultDateDisplayFormat = 'd/m/Y');
DateTimePicker::configureUsing(fn () => DateTimePicker::$defaultDateTimeDisplayFormat = 'd/m/Y H:i');
Table::configureUsing(fn () => Table::$defaultDateDisplayFormat = 'd/m/Y');
Table::configureUsing(fn () => Table::$defaultDateTimeDisplayFormat = 'd/m/Y H:i');
Schema::configureUsing(fn () => Schema::$defaultDateDisplayFormat = 'd/m/Y');
Schema::configureUsing(fn () => Schema::$defaultDateTimeDisplayFormat = 'd/m/Y H:i');
3 Replies
@silviugd you can configure like so.

Do you need to format it in every place? If it is part of your business rules, could be a better idea to format when you interact with your models. Assuming that you use Laravel 12.x: https://laravel.com/docs/12.x/eloquent-serialization#date-serialization. Also, you can use it with what @Kikechi suggest to you (in create form flows)
Thank you all for your help.
I have addded the defaults in the boot method of the AppServiceProvider, here it is if somebody needs it:
// tables
Table::configureUsing(fn (Table $table) => $table
->defaultDateDisplayFormat('d/m/Y')
->defaultDateTimeDisplayFormat('d/m/Y H:i')
->deferFilters(false));
// infolists
Schema::configureUsing(fn (Schema $schema) => $schema
->defaultDateDisplayFormat('d/m/Y')
->defaultDateTimeDisplayFormat('d/m/Y H:i'));
// datepicker
DatePicker::configureUsing(fn (DatePicker $datePicker) => $datePicker
->native(false)
->closeOnDateSelection()
->defaultDateDisplayFormat('d/m/Y'));
// datetimepicker
DateTimePicker::configureUsing(fn (DateTimePicker $dateTimePicker) => $dateTimePicker
->native(false)
->defaultDateTimeDisplayFormat('d/m/Y H:i'));