Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda