Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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.

Calculating the Last Day in a Week Number

by Allen Wyatt
(last updated May 1, 2017)

6

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)+((B1-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, and 2013. You can find a version of this tip for the older menu interface of Excel here: Calculating the Last Day in a Week Number.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Adding Items to a Context Menu

Context menus can be very helpful for presenting common operations you can perform, based on the context in which the menu is ...

Discover More

Converting from SuperCalc

The scrapheap of computing history is littered with programs that had their moment in the sun and then fell by the wayside. ...

Discover More

Transposing Letters

My fat fingers sometimes result in typing letters in the wrong order. Here's a quick tool that allows you to easily transpose ...

Discover More

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!

More ExcelTips (ribbon)

Calculating Weekend Dates

Do you look forward to the weekend? Well, you can use Excel to let you know when the next weekend begins. Here's how you can ...

Discover More

Converting Mainframe Date Formats

Different industries and different computer systems specify dates in all sorts of strange ways. If you need to convert a date ...

Discover More

Calculating the First Business Day of the Month

Want to know which day of the month is the first business day? The easiest way to determine the date is to use the WORKDAY ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven minus 2?

2015-05-28 10:19:34

Michael (Micky) Avidan

@Mohammad A. R,
My I suggest a MUCH shorter formula to achieve you task ?
Please check the following:
=DATE(YEAR(TODAY()),1,1)+((1-(7>=WEEKDAY(DATE(YEAR(TODAY()),1,1))))*7)+(7-WEEKDAY(DATE(YEAR(TODAY()),1,1)))
I have a strange feeling that by using the WORKDAY.INTL function the formula can by shorten even more.
(Didn't have time to check this out).
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL


2015-05-26 14:17:07

Mohammad A. R.

Here's the formula for the 1st day in the week for the current year. In my country, 1st day is Saturday so this is based on Sat as 1st day:

=IF(YEAR(DATE(YEAR(TODAY()),1,6-WEEKDAY(DATE(YEAR(TODAY()),1,1),16)+((6-WEEKDAY(DATE(YEAR(TODAY()),1,1),16)<0)*7)+1)+((B1-1)*7)+1)=YEAR(TODAY()),DATE(YEAR(TODAY()),1,6-WEEKDAY(DATE(YEAR(TODAY()),1,1))+((6-WEEKDAY(DATE(YEAR(TODAY()),1,1))<0)*6)+1)+(((B1-1)*7)+1),"")


2015-05-26 14:10:23

Mohammad A. R.

@ Tom & Juan

B1 is the week number

You need to multiply it by 7 to calculate the number of days between the beginning of the year and the desired week number

This way, you get the date of the last day in that weeknum. With some tweaks to the formula, you get the 1st day of that week as well


2014-08-11 08:53:31

Glenn Case

Tom:

See the second paragraph in the tip.


2014-08-08 13:28:51

Tom

Juan, I was wondering the same thing... What is B1?


2013-04-28 15:47:43

Juan

These formulas sounds very complicated. Why do I have to multiply B1 times 7 and then substract the weekday of January 1st of the year?


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.