Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

325
Visualizações
Change date filtering format for datatables js

I'm filtering by date range using datatables js.

My range filtering works well if the dates in the table are in YYYY/MM/DD format.

 <div class="input-group my-3">
  <input class="form-control" type="date" id="min" name="min">
  <input class="form-control" type="date" id="max" name="max">
 </div>

Filter code:

 $('#min, #max').on('change', function () {
  $.fn.dataTable.ext.search.push(
    function( settings, data, dataIndex ) {
      var min = new Date($('#min').val());
      var max = new Date($('#max').val());
      var date = new Date(data[$('#dateCol').index()]);
      
      if (
        ( min === null && max === null ) ||
        ( min === null && date <= max ) ||
        ( min <= date && max === null ) ||
        ( min <= date && date <= max )
      ) {
        return true;
      }
      return false;
    }
  );
  table.draw();
});

But I need to display dates in the table in the format DD.MM.YYYY. If I display this format, then the filter is broken. As I understand it, instead of December (month 12), it displays all 12 numbers.

If I enter these dates:

enter image description here

The table is filtered like this:

enter image description here

But if I change the display of dates in the table to YYYY/MM/DD, then everything is filtered as needed.

enter image description here

Console.log input:

enter image description here

Console.log data:

enter image description here

If you change the date display format, then the "Invalid date" error disappears.

Changed format to YYYY/MM/DD console.log:

enter image description here

Help me solve this please

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda