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

noblemfd's avatar

How to force date format to dd/mm/yyyy

In my Laravel-5.8 project, I have this code:

Model

  protected $fillable = [
              'name',
              'start_date',
              'end_date',
          ];

protected $dates = [
    'start_date',
    'end_date'
    ];

View:

  <td>
     <input type="date" name="start_date[]" placeholder="dd/mm/yyyy" class="form-control start_date" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}">
  </td>

  <td>
     <input type="date" name="end_date[]" placeholder="dd/mm/yyyy" class="form-control end_date" min="{{Carbon\Carbon::now()->firstOfYear()->format('Y-m-d')}}" max="{{Carbon\Carbon::now()->lastOfYear()->format('Y-m-d')}}">
     </td>

With this, I expected the date to display as dd/mm/yyyy, but it still comes as mm/dd/yyyy

Some systems display it as dd/mm/yyyy while others as mm/dd/yyyy

However, I want it to be:

dd/mm/yyyy

How do I resolve this?

Thank you

0 likes
6 replies
Aronaman's avatar

@noblemfd use accesor in your model or in your app.config add some code like this 'date_format' => 'd/m/Y', 'date_format_javascript' => 'DD/MM/YYYY', then pull it in all view or controller . are u from Ethiopia?

Aronaman's avatar

i dont see the full blade, i think it is datepicker , if so you should do this

if you are using a data picker or any js date.

$('.date').datepicker({
    format: '{{ config('date_format_javascript') }}'
});

or may be you just fill the date manually in your input. do this in your controller

(Carbon::parse($request->start_date)->format('j F, Y') )

in blade

<td>{{ date( config('date_format'),  strtotime($expenses->date)) }}</td>
noblemfd's avatar

@aronaman - I did this in config/app

return [
	'date_format' => 'd/m/Y',
	 'date_format_javascript' => 'DD/MM/YYYY',
];

I got this error:

Syntax error unexpected: return after: ','

and this is underlined red:

return [

frankielee's avatar

Have you tried to implement the mutator?

 	protected $dateFormat = 'd/m/Y';//if you want to store it as this format

    public function getStartDateAttribute($value)
    {
        return Carbon::createFromFormat('d/m/Y' ,$value); //only to display
    }
Aronaman's avatar
Aronaman
Best Answer
Level 2

@noblemfd it should work

<?php

return [



    /*
    |--------------------------------------------------------------------------
    | Application Environment
    |--------------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services the application utilizes. Set this in your ".env" file.
    |
    */

    'env' => env('APP_ENV', 'production'),

    /*
    |--------------------------------------------------------------------------
    | Application Debug Mode
    |--------------------------------------------------------------------------
    |
    | When your application is in debug mode, detailed error messages with
    | stack traces will be shown on every error that occurs within your
    | application. If disabled, a simple generic error page is shown.
    |
    */

    'debug' => env('APP_DEBUG', false),

    /*
     Date Format 
    */
        'date_format' => 'd/m/Y',
        'date_format_javascript' => 'DD/MM/YYYY',

it is not working, try mutators

in your model

protected $dates = [
        'created_at',
    ];

    public function getCreatedFormatAttribute()
    {  
        return $this->created_at->format('d-m-Y');
    }
  protected $appends = ['created_format'];

then in view blade do this

{{$anyVarible->created_format}}

Please or to participate in this conversation.