Calculate current week number in JavaScript Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Calculating the current week number involves determining which week of the year the current date falls into. The method of calculation can vary slightly depending on the rules you follow, such as which day starts the week (Sunday or Monday) and how the first week of the year is defined.For example:January 1st might fall into the last week (week 52 or 53) of the previous year or the first week of the current year, depending on the day of the week it lands on.If January 1st is a Monday, then it will be considered the first week of the new year.Here's an approach to calculate the current week number based on the assumption that weeks start on Monday.Approach:Date Initialization: Ensure currentDate is set to either the provided date object or the current date using new Date().Calculate January 1st: Initialize januaryFirst to the beginning of the current year using new Date(currentDate.getFullYear(), 0, 1).Days to Next Monday: Determine the number of days to the next Monday from January 1st using conditional logic.Calculate Next Monday: Set nextMonday to the date of the next Monday following January 1st.Return Week Number: Compare currentDate with nextMonday and calculate the week number accordingly, returning the result.Example: In this example, we are calculating the total number of weeks till now. JavaScript function getDateWeek(date) { const currentDate = (typeof date === 'object') ? date : new Date(); const januaryFirst = new Date(currentDate.getFullYear(), 0, 1); const daysToNextMonday = (januaryFirst.getDay() === 1) ? 0 : (7 - januaryFirst.getDay()) % 7; const nextMonday = new Date(currentDate.getFullYear(), 0, januaryFirst.getDate() + daysToNextMonday); return (currentDate < nextMonday) ? 52 : (currentDate > nextMonday ? Math.ceil( (currentDate - nextMonday) / (24 * 3600 * 1000) / 7) : 1); } const currentDate = new Date(); const weekNumber = getDateWeek(); console.log("Week number of " + currentDate + " is : " + weekNumber); OutputWeek number of Mon Mar 11 2024 04:57:07 GMT+0000 (Coordinated Universal Time) is : 11 Comment More info P pulamolusaimohan Follow Improve Article Tags : JavaScript Web Technologies javascript-date JavaScript-Questions Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like