Reputation: 51
i'm trying to convert date (from a input type="date") to miliseconds but my output is "NaN, NaN" for some reason.
HTML code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Stats</title>
<h1>Stats</h1>
</head>
<body>
<div class="contenedorFechas" for="fechas">
<p>Insert date to promediate temps and humidity</p>
<input type="date" id="fechaUno">
<input type="date" id="fechaDos">
<input type ="button" id="btnPetDatos" value="Solcitar">
<p id="pRespuesta">...</p>
</div>
</body>
<script src="metodosJS.js" type="text/javascript"></script>
</html>
Javascript:
document.getElementById("btnPetDatos").onclick = function (){
var auxUno = new Date(document.getElementById("fechaUno").value);
var auxDos = new Date(document.getElementById("fechaDos").value);
var fechaUno = auxUno.getMilliseconds();
var fechaDos = auxDos.getMilliseconds();
var Parametros = [fechaUno,fechaDos];
document.getElementById("pRespuesta").innerHTML = Parametros;
}
Upvotes: 1
Views: 85
Reputation: 17610
You forgot to take value of date elements
document.getElementById("btnPetDatos").onclick = function (){
var auxUno = new Date(document.getElementById("fechaUno").value);
var auxDos = new Date(document.getElementById("fechaDos").value);
var fechaUno = auxUno.getMilliseconds();
var fechaDos = auxDos.getMilliseconds();
var Parametros = [fechaUno,fechaDos];
document.getElementById("pRespuesta").innerHTML = Parametros;
}
And are u sure to use getMilliseconds()
method because u choose time so there is not hour or minute so u will take 0 always.
u can use getTime()
method it return an integer to you. So you can use them how you want.
Upvotes: 1