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

141
Vistas
Api: sort id base on start dates and hours in javascript

I would like to sort dates according to each id and when an id is passed it will appear in a "passed id" section, if it is in progress in a "current" section and if it is not in progress passed in a "coming soon" section. Start and end have this format: start: '2021-04-26T13:00:00.000Z', end: '2021-04-26T15:30:00.000Z'

Thank you !

here is my code :

fetch(urlCourses)
  .then(res => res.json())
  .then(function (data) {

    let donnees = data;

    //console.log( JSON.stringify(tabStudents));
  donnees.forEach(e => {
      tabCourses.push({
        'id': e.id,
        'name': e.name,
        'start': e.start,
        'end': e.end,
        'school_id': e.school_id,
       
        //'students': e.STUDENTS,
        'classroom': e.classroom
      });
    });
   
    tabCourses.sort(function (a, b) {
      return new Date(a.start) - new Date(b.start);
    });
    
   console.log('tabCourses sorted', tabCourses);

  
  })
  .catch(function (error) {
    console.log(error);
  });
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If you want to sort by a column and then by another column, I can refer you to this answer. (the brilliant one) sort Javascript array by two numeric fields

Should you want to sort into 3 distinct lists according to the value of dates (start, end and current) then first you want to run over the array, adding a column named "section" with possible values of : "passed", "progress", "future".

Then you can sort by it or separate it into 3 lists.

I leave it to you or others to write the code for that.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Convert your date in timestamp and it will do the trick

    tabCourses.sort(function (a, b) {
  return new Date(a.start).getTime() - new Date(b.start).getTime();
});
about 4 years ago · Juan Pablo Isaza Denunciar
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