I have the following problem. I have a function that counts down. At the moment, I have it static, but the value will come from a query to the bd to calculate today's date and compare it with the date to subtract. This is the function:
function faltan() {
var futuro = new Date(2018, 07, 14, 22, 40);
var actualiza = 1000;
var ahora = new Date();
var faltan = futuro - ahora;
// si todavís no es futuro
if (faltan > 0) {
var segundos = Math.round(faltan / 1000);
var minutos = Math.floor(segundos / 60);
var segundos_s = segundos % 60;
var horas = Math.floor(minutos / 60);
var minutos_s = minutos % 60;
var dias = Math.floor(horas / 24);
var horas_s = horas % 24;
// escribe los resultados
(segundos_s < 10) ? segundos_s = "0" + segundos_s : segundos_s = segundos_s;
(minutos_s < 10) ? minutos_s = "0" + minutos_s : minutos_s = minutos_s;
(horas_s < 10) ? horas_s = "0" + horas_s : horas_s = horas_s;
(dias < 10) ? dias = "0" + dias : dias = dias;
var resultado = dias+ ":" + horas_s + ":" + minutos_s + ":" + segundos_s;
//document.formulario.reloj.value = resultado;
document.formulario.reloj.value = resultado;
//actualiza el contador
setTimeout("faltan()", actualiza);
}
// estamos en el futuro
else {
//document.formulario.reloj.value = "00 dias : 00 horas : 00 minutos : 00 segundos";
document.formulario.reloj.value = "Tiempo Expirado";
}
}
that function calculates the remaining time in days, hours, minutes and seconds. The future variable (future var), will contain the value extracted from the database. This is where it is shown in the table generated in datatables:
{
"sClass": "alignRight",
"data" : null,
'render': function (data, type, row, meta) {
return "<form name='formulario'><input type='text' name='reloj' size='10' style='border : 0px ; text-align : center'>"
"</form>";
}
}
The problem I have is how to declare the future variable (future var) within datatables so that I can use it later in the function that calculates the remaining time. it should be noted that the values that will come from the database, is in format YYYY-DD-MM HH: MM: SS.
If information is missing, I will gladly provide it. I appreciate any help and / or guidance in this regard. Greetings to all.