title: Correct way to use Date format in laravel
body: <p>i have a Laravel project with Postgres database. I have some problems with date format.</p>
  <p>This is a piece of input field in Laravel blade</p>
  <pre class="lang-html prettyprint-override"><code>&lt;div class=&quot;form-group col-md-3&quot;&gt;
       &lt;label for=&quot;nome&quot; class=&quot;required&quot;&gt;
         Birth Date
       &lt;/label&gt;
       &lt;input class=&quot;form-control date&quot; type=&quot;text&quot;value=&quot;{{ (!empty($patient) &amp;&amp; $patient-&gt;datebirth) ? 
       Carbon\Carbon::parse($patient-&gt;datebirth)-&gt;format('d/m/Y') : '' }}&quot;  name=&quot;datebirth&quot; 
       id=&quot;datebirth&quot; /&gt;
  &lt;/div&gt;
  </code></pre>
  <p>And this is the script that activate the bootstrap date field</p>
  <pre class="lang-php prettyprint-override"><code>$(document).ready(function() {
      $('.date').datepicker({
          firstDayOfWeek: 1, // The first day of week is Monday
          weekDayFormat: 'narrow', // Only first letter for the weekday names
          inputFormat: 'd/M/y',
          outputFormat: 'd/M/y',
          titleFormat: 'EEEE d MMMM y',
          markup: 'bootstrap4',
          theme: 'bootstrap',
          modal: false
      });
  });
  </code></pre>
  <p>This is the controller code</p>
  <pre class="lang-php prettyprint-override"><code>public function save(Request $req){
      $validatedData  = $req-&gt;validate([
          'name' =&gt; ['required', 'max:255'],
          'datebirth' =&gt; ['required','date'],
      ]);
  
     $newPatient = new Patient;
     $newPatient-&gt;name = $req-&gt;name;
     $newPatient-&gt;datebirth = $req-&gt;datebirth;
     $newPatient-&gt;save();
  }
  </code></pre>
  <p>But when i save the object the error is:</p>
  <pre><code>SQLSTATE[22008]: Datetime field overflow: 7 ERROR: date/time field value out of range: &quot;22/04/1985&quot;...
  </code></pre>
  <p>Because the database want y m d format, but i want to use in my views d/M/y. I i change the outputFormat: in 'y/M/d' the save operation works, but when the user changes the date using the widget (input field), it is shown in the format y/M/d.</p>
  <p>in the controller I simply take the value of the datebirth field of the request, i assign it to the object and save it. I would like to avoid doing format conversions in the controller every time I save / edit the object</p>
  <p>What is the right way to manage this situation?</p>
  <p>is there any way to avoid converting the data format every time before saving?</p>