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

101
Vistas
Need help slicing date value

result_database = [
  { id: 1, name: "Tom Riddle", date: "2022-05-16T22:00:00.000Z" },
  { id: 2, name: "Hank Some", date: "2022-05-19T22:00:00.000Z" },
  { id: 3, name: "Family Man", date: "2022-05-17T22:00:00.000Z" },
];
var holiday_date = new Date().toJSON().slice(0, 10);
let holiday_date_remove = result_database.filter(
  (item1) =>
    !result_database.find(
      (item2) =>
        item1.name == item2.name && item2.date.slice(0, 10) == holiday_date
    )
);
const holiday_result = [
  ...new Map(
    holiday_date_remove.map((item) => [JSON.stringify(item.name), item])
  ).values(),
];
console.log(holiday_result);

I'm trying to .slice(0,10) the date. I get it displayed like this "2022-05-16T22:00:00.000Z", but I need it as "2022-05-16", so I try to date.slice(0, 10) it's not working though.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

const dataDate = '2022-05-17T22:00:00.000Z' 

const date = new Date(dataDate)

date.getDate()  + "-" + (date.getMonth()+1) + "-" + date.getFullYear()

console.log(date)

For more information regarding date formats read here

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can first map over result_database using Array.prototype.map and update the date property and then filter the array based on holiday_date using Array.prototype.filter.

const 
  result_database = [
    { id: 1, name: "Tom Riddle", date: "2022-05-16T22:00:00.000Z" },
    { id: 2, name: "Hank Some", date: "2022-05-19T22:00:00.000Z" },
    { id: 3, name: "Family Man", date: "2022-05-17T22:00:00.000Z" },
  ],
  holiday_date = new Date().toJSON().slice(0, 10),
  holiday_date_remove = result_database
    .map((item) => ({ ...item, date: item.date.slice(0, 10) }))
    .filter(({ date }) => date !== holiday_date);

console.log(holiday_date_remove);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You should split by "T" when it's in ISOString format.

const yourTypeDate = new Date().toISOString().split('T')[0];

This comparing below is working, it will check if the db date is equal today date, if it's will remove the index, the filter is working.

result_database = [
  { id: 1, name: "Tom Riddle", date: "2022-05-16T22:00:00.000Z" },
  { id: 2, name: "Hank Some", date: "2022-05-19T22:00:00.000Z" },
  { id: 3, name: "Family Man", date: "2022-05-17T22:00:00.000Z" },
];
var holiday_date = new Date().toISOString().split('T')[0];
let holiday_date_remove = result_database.filter(
  (item1) =>
    !result_database.find(
      (item2) => {
        item2.date = item2.date.split('T')[0];
        return ((item1.name == item2.name) && (item2.date.split('T')[0] == holiday_date));
        }
    )
);
const holiday_result = [
  ...new Map(
    holiday_date_remove.map((item) => [JSON.stringify(item.name), item])
  ).values(),
];
console.log(holiday_result);

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