Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Calculating the Last Day in a Week Number.
Written by Allen Wyatt (last updated October 21, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
You probably know that you can use the WEEKNUM function to return the week number in a year for a given date. What if you want to do the reverse—to determine the last day of a particular week if all you have is the week number within the year? For instance, if you were to specify week 37, you would like to figure out the date of the last day in that particular week.
There is no built-in function to figure out the desired date, but there are a number of ways that you can approach the problem and figure it out. In these examples we will assume that the year is in cell A1 and the desired week number is in cell B1.
The first approach is to calculate the first day of the desired year, add seven days for each of the weeks, and then subtract the weekday number for the first day of the year.
=DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1))
This formula returns a date that always represents the last day of the week, if the week ends on a Saturday. If you want the week to end on a different day of the week then the formula becomes more complex. If you want the week to end on a Sunday, then you simply need to add 1 to the formula:
=DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1))+1
Applying this same logic, you might think that you could figure out weeks ending on Friday by simply subtracting 1 from the formula. This is not the case since you are using the beginning of the year as your base. If you subtract 1, you run into the problem where January 1 of whatever year is a Saturday; if you subtract 1 you don't end up with the first Friday of the year but instead end up with December 31 of the previous year. To calculate for weeks ending on Friday you need a much more complex formula:
=DATE(A1,1,6-WEEKDAY(DATE(A1,1,1))+ ((6-WEEKDAY(DATE(A1,1,1))<0)*7)+1)+((B1-1)*7)
Since some years have 52 weeks and some have 53—again depending on whether weeks end on Friday, Saturday, or Sunday—it is a good idea to modify the formulas so that they check to see if the date being returned is within the same year that you are analyzing. If you don't check this, then the formulas provided thus far will happily return dates for week 73, week 89, or week 123 of any given year—they simply adjust the date into the appropriate future year.
Here is the formula for weeks ending in Friday:
=IF(YEAR(DATE(A1,1,6-WEEKDAY(DATE(A1,1,1))+ ((6-WEEKDAY(DATE(A1,1,1))<0)*7)+1)+((A1-1)*7))=A1, DATE(A1,1,6-WEEKDAY(DATE(A1,1,1))+((6-WEEKDAY(DATE( A1,1,1))<0)*7)+1)+((B1-1)*7),"")
If the date calculated is not in the same year as what is specified in cell A1, then the formula returns nothing. Here is the formula for weeks ending in Saturday:
=IF(YEAR(DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1)))=A1, DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1)),"")
Finally, here is the formula for weeks ending in Sunday:
=IF(YEAR(DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1))+1)=A1, DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1))+1,"")
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12603) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Calculating the Last Day in a Week Number.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
Many businesses need to know when the last business day of the month occurs. This tip discusses several ways you can ...
Discover MoreDon't want to use the EOMONTH function to figure out the end of a given month? Here are some other ideas for discovering ...
Discover MoreThere are calendar days and then there are business days. Excel provides two functions (NETWORKDAYS and NETWORKDAYS.INTL) ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-10-22 14:37:33
J. Woolley
This Tip ignores the optional second argument of the WEEKDAY function (apparently added with Excel 2010; also applies to WEEKNUM):
=WEEKDAY(serial_number,[return_type])
Weekdays are usually numbered 1-7 for Sunday-Saturday. If return_type is omitted, WEEKDAY returns 1-7 for Sunday-Saturday. But if return_type is 16 WEEKDAY returns 1-7 for Saturday-Friday. In general, for weeks that end on day N, where N is 1-7 for Sunday-Saturday, make return_type equal to (10+N).
The Tip says, "If you want the week to end on a Sunday, then you simply need to add 1 to the formula:"
=DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1))+1
But this formula provides the same result:
=DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1),11)
The Tip says, "...you run into the problem where January 1 of whatever year is a Saturday....To calculate for weeks ending on Friday you need a much more complex formula:"
=DATE(A1,1,6-WEEKDAY(DATE(A1,1,1))+
((6-WEEKDAY(DATE(A1,1,1))<0)*7)+1)+((B1-1)*7)
But this formula provides the same result:
=DATE(A1,1,1)+B1*7-WEEKDAY(DATE(A1,1,1),16)
The following dynamic array function in My Excel Toolbox helps to visualize these results:
=ListCalendar([YearNum],[MonthNum],[NumMonths],[SkipHeader],[FirstDayOfWeek])
The default value for FirstDayOfWeek is 1 (Sunday). Here is the result for January 2022 because New Year's Day was a Saturday (see Figure 1 below)
The SpillArray function (described in UseSpillArray.pdf) simulates a dynamic array in older versions of Excel.
See https://sites.google.com/view/MyExcelToolbox
Figure 1.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments