Put variable within input type="date"

0

How can I put this variable inside input

var data = new Date();
    var dataCurrente = new Date();
    if (data > dataCurrente) {
        alert("Data maior que atual");
    }

In case the new date() has to be the date I put in input type="date" .

    
asked by anonymous 28.03.2018 / 19:02

1 answer

2

I put Alert's just to see how you are setting the date until the final presentation.

var agora = new Date();
alert(agora);

var dia = ("0" + agora.getDate()).slice(-2);
alert("Hoje é dia: " + dia);

var mes = ("0" + (agora.getMonth() + 1)).slice(-2);
alert("Do mês: " + mes);

var dataHoje = agora.getFullYear()+"-"+(mes)+"-"+(dia);
alert("Data formatada para o campo: " + dataHoje);

$('#campoQueVoceQuerSetarValor').val(dataHoje);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputid="campoQueVoceQuerSetarValor" type="date"></input>

Although the presentation in the field will be dd/MM/yyyy , note that the form that goes there is yyyy/MM/dd .

    
28.03.2018 / 19:53