Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

324
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!