Display a date in one format and store it in another (Datepicker in Laravel)

0

I am working in laravel and I want to show in my Bootstrap Datepicker field a date in a format (dd / mm / yyyy) but I want to store it in format (yyyy / mm / dd).

Is there any property in Datepicker to do that? This is my input:

<div class="form-group">
  <label for="fecha_nac"></label>
  <input type="text" class="form-control CalendarioDP" 
         name="fecha_nac" placeholder="Colocar fecha"
         value="{{ Carbon\Carbon::now()->formatLocalized('%d/%m/%Y') }}">
</div>

My Script:

<script>
    $('.CalendarioDP').datepicker({
        format: "dd/mm/yyyy",
        language: "es",
    });
</script>

When I leave the format in the script in this way, the date is displayed and stored in a format (dd / mm / yyyy)

I want to store it in (yyyy / mm / dd).

I have used "Torzer DateTime Mutator" and "protected $ dates", but I want to know if there is a simple DaterPicker property to declare once in the script and not specify each field I want to convert as Torzer

    
asked by Eduardo Quiñonez 13.09.2018 в 20:18
source

1 answer

1

A solution is that you can do is when you pass the values to the controller separate it as follows and then join it:

  • $ date="2006/05/04";
  • $ year = substr ($ date, -10, 4);
  • $ month = substr ($ date, -5, 2);
  • $ dia = substr ($ date, -2, 2);

and then join it to another php variable, so that you have the format you want.

    
answered by 17.09.2018 в 22:11