Convert MMMM-YYYY data to dd / mm / yyyy datepicker bootstrap

9

I have the following date field:

<div class='input-group date input-data' id='datetimepicker4'>
    <input type='text' name="mes" id="mes" class="form-control hidden" />
    <span class="input-group-addon hidden">
        <span class="glyphicon glyphicon-calendar"></span>
    </span>
</div> 

 $('#datetimepicker4').datetimepicker({
    format: 'MMMM-YYYY',
    locale: 'pt-br',
    defaultDate: new Date() 
});

This format is displayed: September-2016. How do I display in this format and then convert to 01/09/2016?

    
asked by anonymous 29.09.2016 / 13:44

1 answer

2

In PHP, we can create a function called converterData , and return the month and year in the format you want.

<?php

$data = "setembro-2016";

function converterData($data) {
  $meses = Array(
    "janeiro" => "01",
    "fevereiro" => "02",
    "março" => "03",
    "abril" => "04",
    "maio" => "05",
    "junho" => "06",
    "julho" => "07",
    "agosto" => "08",
    "setembro" => "09",
    "outubro" => "10",
    "novembro" => "11",
    "dezembro" => "12"
  );
  $data = explode("-", $data);
  $mes = $meses[$data[0]];
  $ano = $data[1];
  return "01/$mes/$ano";
}

print converterData($data);
# -> 01/09/2016

?>
    
07.10.2016 / 04:36