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

95
Vistas
Checking for date isWeekend for array of dates - Javascript

I would like to check which days are weekends in my array. For now I only managed to check on single dates, and not the whole array at once.

If it is a weekend I would like to change the color on my barchart. Any help would be much appreciated.

const dates = ['2022-07-15', '2022-07-16', '2022-07-17', '2022-07-18', '2022-07-19', '2022-07-20']

function isWeekend(date = new Date()) {
    return date.getDay() === 6 || date.getDay() === 0;
  }

  const d1 = new Date(dates);

  console.log(d1.getDay()); 

  console.log(d1.isWeekend()); 

  const data = {
    labels: dates,
    datasets: [
      {
        label: "Amount of Visitors",
        data: [1, 4, 3, 7, 5, 2],
        backgroundColor: "rgba(255, 99, 132, 0.5)",
      },
    ],
  };
almost 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Your isWeekend function looks good (ignoring time zone support), you likely just need to set the background colors in your bar chart:

const data = {
  labels: dates,
  datasets: [
    {
      label: 'Amount of Visitors',
      data: [1, 4, 3, 7, 5, 2],
      backgroundColor({ dataIndex }) {
        return isWeekend(new Date(dates[dataIndex])) ? 'green' : 'red';
      },
    },
  ],
};

https://codesandbox.io/s/check-for-dates-on-weekends-dv07np?file=/src/Visitors.js

almost 4 years ago · Santiago Trujillo Denunciar

0

const dates = ['2022-07-15', '2022-07-16', '2022-07-17', '2022-07-18', '2022-07-19', '2022-07-20'];
function isWeekEnd(date){
  var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  var day = new Date(date);
  var dayName = days[day.getDay()];
  console.log(dayName);
  switch (dayName) {
    case 'Friday':
      return true
      break;
    case "Saturday":
      return true
      break;
    default:
      return false
  }
}
for(var i=0;i<dates.length;i++){
  console.log(isWeekEnd(dates[i]));
}

almost 4 years ago · Santiago Trujillo 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