Date in odd fractional form 0.00xxxxxxx

3

I get this date from DB:

  

0.002976190476190476

I would like to pass this format: dd/mm/yyyy , using javascript pure or jquery .

How do I do it?

Here is the ASP that mounts the select:

strsql = ""
                strsql = "select a.cod_operadora, a.nom_operadora, to_char(b.dat_exclusao,'dd/mm/yyyy') dat_exclusao, case when b.dat_exclusao is null then 'N' else 'S' end excluido "
                strsql = strsql & " from ts_odo.odo_operadora             a "
                strsql = strsql & "     ,ts_odo.odo_prestador_operadora   b "
                strsql = strsql & "where a.cod_operadora    = b.cod_operadora "
                strsql = strsql & "  and b.cod_prestador_ts = " & cod_prestador_ts
                strsql = strsql & "order by to_number(a.cod_operadora)"                     

                set TopDB = server.CreateObject("TSDB.Data")

                set rsOperadora = TopDB.objrs ( CStr(txt_usuario), _
                                                CStr(txt_senha), _
                                                CStr(txt_ip), _
                                                session("ace_sistema"), _
                                                CStr(txt_modulo), _
                                                strsql)
                set TopDB = nothing 

And here's the call to the js method, which is within a while in asp:

Response.Write "<script>montaDataSubstituicaoPrestador(" & rsOperadora("dat_exclusao") & ")</script>"

And this is the js function that should do what I want, print a label on the calculated date.

function montaDataSubstituicaoPrestador(dt_exclusao){

    alert('Paulo: ' + dt_exclusao);

    var arrData = dt_exclusao.split('/');
    var exclusaoFormatada = arrData[1] + '-' + arrData[0] + '-' +  arrData[2];
    var dias = parseInt(prazoSubPrestador);
    var novaData = new Date(arrData[2], arrData[1] - 1, arrData[0]);

    novaData.setDate(novaData.getDate() + dias);

    hoje = new Date(novaData)
    dia = hoje.getDate()
    mes = hoje.getMonth()
    ano = hoje.getFullYear()
    if (dia < 10)
        dia = "0" + dia

    if((mes+1) < 10)
        mes = "0" + (mes+1);

    if (ano < 2000)
        ano = "19" + ano

    var dt = dia + "/" + (mes) + "/"+ano;

    var elem = document.getElementById('ind_exclusao_voluntaria');

    if(elem.value == 'S')
        document.getElementById('lblPrazoSubPrestador').innerHTML = "Prazo de substituição: " + dt;
    else
        document.getElementById('lblPrazoSubPrestador').innerHTML = "";
}
    
asked by anonymous 04.01.2016 / 18:01

1 answer

2

The problem may be in this stretch

Response.Write "<script>montaDataSubstituicaoPrestador(" & rsOperadora("dat_exclusao") & ")</script>"

You are passing the parameter without quotation marks. Since the value is numeric and contains the mathematical character of / division, a mathematical operation is taking place at the time the parameter is informed in the invocation of the rsOperadora() function.

To resolve this, enter the quotation-delimited parameter to be treated as a string.

Suggestion:

Response.Write "<script>montaDataSubstituicaoPrestador('" & rsOperadora("dat_exclusao") & "')</script>"

I just delimited with single quote. This ensures that the value is read as a string.

obs: I do not know for sure this is what happens because the information in the question is confusing and vague.

Explanation of how I came to this deduction

Deduct because of the format of the 0.002976190476190476 value. The first thing I imagined is, how did you get a date to come in this format?

By logical deduction imaginei 01/20/2016 (today's date as an example). They are 20 divided by 1 that is divided by 2016, equal to 0.0099206349206349 . Ready! We have the odd format identical to what you posted.

What makes it confusing is that your question "states" that the value already comes from the database. But looking at the query query, it did not make sense. But by looking at this snippet of code & rsOperadora("dat_exclusao") & , it started to make sense where the problem might be.

Checking

To make sure what I've deduced, just run the ASP page normally and read the HTML code generated in the browser. In Chrome, press CTRL + U which will open a window showing the generated HTML code. Search for the <script>montaDataSubstituicaoPrestador( excerpt. You'll probably see that the date is correct, something like <script>montaDataSubstituicaoPrestador(20/01/2016)</script> , however, without the quotation marks. Thus, without quotation marks, a mathematical operation is occurring. Resulting in fractional value.

    
19.01.2016 / 23:13