getDay()

ES1+

Returns the day of the week (0-6) for the specified date according to local time.

Syntax

date.getDay()

Return Value

number

A number (0-6) representing the day of the week (0 = Sunday)

Examples

JavaScript
const date = new Date('2024-01-15'); // μ›”μš”μΌ
const days = ['일', 'μ›”', 'ν™”', '수', 'λͺ©', '금', 'ν† '];
console.log(date.getDay());
console.log(days[date.getDay()] + 'μš”μΌ');
Output:
// 1 μ›”μš”μΌ

πŸ“Œ When to Use

Use getDay() for calendar rendering, business day calculations, weekend detection, or scheduling logic based on day of week.

⚠️ Common Mistakes

Assuming getDay() returns 1-7 like some other programming languages - JavaScript uses 0-6.

Forgetting that Sunday is 0, not 7, which can cause off-by-one errors in arrays.

βœ… Best Practices

Check for weekends with: const isWeekend = date.getDay() === 0 || date.getDay() === 6.

For localized day names, use toLocaleString: date.toLocaleString(locale, { weekday: "long" }).

⚑ Performance Notes

getDay() is O(1). For repeated weekend checks in loops, inline the comparison rather than calling a function for marginal gains.

🌍 Real World Example

Business Days Calculator

Calculate delivery date by adding business days, skipping weekends.

function addBusinessDays(startDate, daysToAdd) {
  const result = new Date(startDate);
  let addedDays = 0;

  while (addedDays < daysToAdd) {
    result.setDate(result.getDate() + 1);
    const dayOfWeek = result.getDay();

    // Skip weekends (0 = Sunday, 6 = Saturday)
    if (dayOfWeek !== 0 && dayOfWeek !== 6) {
      addedDays++;
    }
  }

  return {
    deliveryDate: result.toLocaleDateString(),
    dayOfWeek: result.toLocaleString('en-US', { weekday: 'long' }),
    businessDays: daysToAdd
  };
}

console.log(addBusinessDays('2024-03-15', 5)); // Friday + 5 business days
// { deliveryDate: '3/22/2024', dayOfWeek: 'Friday', businessDays: 5 }

Related Methods