📅Date & Time

Calendar Week (ISO)

How to calculate the current week number (1-53).

Explanation

The ISO week-numbering year system defines week 1 as the week containing the first Thursday of the year.

Examples

First Week
Output
Week 01
Last Week
Output
Week 52 or 53

Code Examples

JavaScript
function getISOWeek(date) {
  const d = new Date(date.getTime());
  d.setHours(0, 0, 0, 0);
  d.setDate(d.getDate() + 4 - (d.getDay() || 7));
  const yearStart = new Date(d.getFullYear(), 0, 1);
  return Math.ceil((((d.getTime() - yearStart.getTime()) / 86400000) + 1) / 7);
}

💡 Tips

  • Weeks start on Monday in ISO 8601
  • Some years have 53 weeks
  • Commonly used in logistics and planning

⚠️ Common Pitfalls

  • US week system (starting Sunday) is different
  • Week 1 of 2024 might include days from 2023