Jump to content
Fórum Script Brasil
  • 0

Conversão De Datas - Javascript


Fabiano Campos
 Share

Question

Olá, galera.

Tenho a seguinte situação: Preciso calcular a dif de dias entre duas datas. A estrutura para o cálculo está ok, porém ele pega o formato de data mm/dd/yyyy.

Eu preciso calcular no formato dd/mm/yyyy. Estou calculando da seguinte forma:

//### Cálculo automático de diárias HOTEL NAC ###
function diasDecorridosHotelNac(){

    var dataCheckin  = window.document.getElementById("subviewHotel:data_checkin").value;
        window.alert(dataCheckin)
    var dataCheckout = window.document.getElementById("subviewHotel:data_checkout").value;
        window.alert(dataCheckout)
    
    var pDataCheckin = new Date (dataCheckin);
      var pDataCheckout = new Date (dataCheckout);
                
      var difDias = Math.abs(Math.round((pDataCheckout-pDataCheckin)/86400000));
          window.alert(difDias)

      window.document.getElementById("subviewHotel:qtdDiarias").value = difDias;
            
}

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...