2

I am trying to change date format in laravel from mm-dd-yyy to dd-mm-yyyy

<input type="date" class="form-control" name="joining_date" id="joining_date" required>

I tried even to put timezone="[[timezone]]" but nothing changes.

Barry
  • 3,303
  • 7
  • 23
  • 42
alphal
  • 149
  • 3
  • 3
  • 14

4 Answers4

3

Convert that date in controller before feeding to database like this :

$originalDate = $request->joining_date;
$newDate = date("dd-mm-YYYY", strtotime($originalDate));

Or if you want to show in view the same date

{{ date("dd-mm-YYYY", strtotime($date_from_controller)); }}

if you want to pre populate input field then

<input type="date" class="form-control" name="joining_date" id="joining_date" value="{{ date("dd-mm-YYYY", strtotime($date_from_controller)); }}" required> 

if you want to change the format of input date then

<input type="text" name="input" placeholder="dd-mm-yyyy" required pattern="(?:30))|(?:(?:0[13578]|1[02])-31))/(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])/(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])">

Hope this helps you.

syam
  • 892
  • 8
  • 19
0
Carbon::createFromFormat('mm-dd-yyy', $input)
  ->format('dd-mm-yyyy'); `
  • 1
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Nic3500 Sep 19 '18 at 15:16
  • Furthermore this does not solve op's problem since he wants to change the format of the input, not the output. – milo526 Sep 19 '18 at 15:27
0

You should try this:

$date =  date('d-m-Y', strtotime($request->date));
0
date_create_from_format('mm-dd-yyy', $input)->format('dd-mm-yyyy');
kgbph
  • 841
  • 1
  • 8
  • 26