Treat date correctly

Asked

Viewed 78 times

0

I have an agenda where I am using the Fullcalendar library (javascript) and when I click on an event I want more information of this to be displayed so far everything right now I have a field form in a modal returned a database date but it returns as I will show below:

Database: Banco de dados

As the date is coming in my desired field:

inserir a descrição da imagem aqui

My code until then:

eventClick: function(event, jsEvent, view){
        $('#id').val(event.id);
        $('#ccod').val(event.codigoCliente);
        $('#mtitulo').val(event.title);
        $('#autor').val(event.autor);
        $('#inicioEdit').val(event.start);
        $('#importanciaEdit').val(event.impor);
        $('#descricaoEventoEdit').val(event.text);
        $('#modalEvento').modal();
      },

Modal:

<div class="row"> 
        <div class="col-md-6">
              <label for="inicio">Data</label>
            </div>
            <div class="col-md-6">
              <label for="importancia">Prioridade</label>
            </div>
          <div class="form-group col-md-6">
            <div class="input-group date">
              <input type="text" class="form-control date" id="inicioEdit" name="data" />
              <div class="input-group-addon">
                <span class="glyphicon glyphicon-th"></span>
              </div>
            </div>
          </div>

I would like a help to be able to put this date returned in the format 'yyyy-mm-dd'

1 answer

0

You can treat the date as follows:

function dataAtualFormatada(){
var data = new Date();
var dia = data.getDate();
if (dia.toString().length == 1)
  dia = "0"+dia;
  var mes = data.getMonth()+1;
 if (mes.toString().length == 1)
  mes = "0"+mes;
  var ano = data.getFullYear();  
 return dia+"/"+mes+"/"+ano;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.