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

103
Views
Necesito ayuda para dividir el valor de la fecha

 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);

Estoy tratando de .slice(0,10) la fecha. Lo veo así "2022-05-16T22:00:00.000Z" , pero lo necesito como "2022-05-16" , así que intento date.slice(0, 10) pero no funciona.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

const dataDate = '2022-05-17T22:00:00.000Z' const date = new Date(dataDate) date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear() console.log(date)

Para obtener más información sobre los formatos de fecha, lea aquí

about 4 years ago · Juan Pablo Isaza Report

0

Primero puede mapear sobre result_database usando Array.prototype.map y actualizar la propiedad de date y luego filtrar la matriz según la fecha de vacaciones usando Array.prototype.filter holiday_date

 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 Report

0

Debe dividir por "T" cuando está en formato ISOString.

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

Esta comparación a continuación está funcionando, verificará si la fecha de la base de datos es igual a la fecha de hoy, si eliminará el índice, el filtro está funcionando.

 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 Report
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!