1
In my form I am using the Bootstrap-Datepicker so that the user can inform the desired date at the time of registration, works correctly, but at the time of making a change I am trying to bring the date of the database in the format 99/99/9999 with the command DATE_FORMAT() via MySQL and return the data via Json but the dates are not being converted and not being positioned in the respective fields, my select is like this:
SELECT *, DATE_FORMAT(DataInicial,'%d/%m/%Y') AS DataInicial, DATE_FORMAT(DataFinal,'%d/%m/%Y') AS DataFinal FROM agendaMural WHERE IdAgenda = 2448
But my console.log shows me this result, the dates are not being converted, I tried the alternatives I knew, see how you are:
The page with the return code is this:
if (jQxhr.responseText != "[]") {
    try {
        if (jQxhr.readyState === 4) {
            if (jQxhr.status === 200) {
                var nota = JSON.parse(jQxhr.responseText);
                //Atribui valores aos campos
                $('#idUnidade').val(nota[0].idUnidade);
                $('#IdDepartamento').val(nota[0].IdDepto);  
                $('#dDataInicial').val(nota[0].DataInicial);        
                $('#dDataFinal').val(nota[0].DataFinal);    
                $('#dHoraInicial').val(nota[0].HoraInicial);        
                $('#dHoraFinal').val(nota[0].HoraFinal);    
                $('#sAssunto').val(nota[0].Assunto);
                $('#sLocal').val(nota[0].Local);
                $('#sDescricao').val(nota[0].Descricao);                    
            } else {
                var dialogInstance = BootstrapDialog.show({
                    title: 'ERRO',
                    type: BootstrapDialog.TYPE_DANGER,
                    message: 'Ocorreu um erro na requisição dos dados. Tente novamente.'
                }); 
            }
        }
    }
						
Hello @Pedro Camara Junior, thanks for the tip, the dates were converted correctly, but they are not being assigned to the respective fields, some hint?
– adventistapr
I made a change in response, created a function to return the formatted date.
– Pedro Camara Junior
What do you mean they’re not being assigned?
– Pedro Camara Junior
Hello @Pedro Camara Junior, thank you for the function. By doing this $("#dDataInicial"). val(Stardate); the date is not appearing in the field.
– adventistapr
Display an error in the browser console? Variable name is correct?
– Pedro Camara Junior
Yes, variable names are correct and no error is shown on the console, I don’t know where I might be missing
– adventistapr
Let’s go continue this discussion in chat.
– Pedro Camara Junior