Calculate weeks in excel

Bottom line: Learn a few tips and techniques for calculating week numbers from dates, the number of weeks between dates, and how to display the week number in cells for reporting.

Skill level: Beginner

3 Tips for Calculating Week Numbers in Excel - Excel Campus - 640x360

As I mentioned in this week’s newsletter, our baby boy was born last week.  Everything went well with the delivery and we are so happy to have our new little 8-pound bundle of joy in our lives.

Baby Acampora 2017

During my wife’s pregnancy, everything was measured in weeks.  There are 40 weeks in a full term pregnancy, we seemed to have a doctor’s appointment every other week, and we were definitely counting down the weeks until his estimated arrival date.

Of course, I kept track of most of these schedules and calculations in Excel.  So, I wanted to share some of the formulas and calculations I used to calculate week numbers.  These tips will also be useful for financial models, data analysis, and summary reports.  Babies aren’t the only things measured in weeks… 🙂

Download the Example File

Download the example Excel file to follow along with the article.

#1 – WEEKNUM Function: Calculate the Week Number of the Year

We can use the WEEKNUM function to quickly determine how many weeks have elapsed from January 1st  to a given date in the same year.  The following formula returns 11 because 11 weeks have elapsed since January 1, 2017.

=WEEKNUM("3/15/2017")
Result: 11

We can also reference a cell that contains a date.  If the date 3/15/2017 was in cell A2, then the following formula would return the same result.

WEEKNUM Function Calculates Number of Weeks Since Jan 1st

=WEEKNUM("A2")
Result: 11

The WEEKNUM function has an optional argument that allows us to specify the day of the week to start on.  By default, WEEKNUM starts the week on Sunday.  We can change that by adding any of the following numbers to the second argument (return_type).  The image below shows the numbers and days for the return_type argument.

WEEKNUM return_type Argument to Specify Start Day of Week

It’s important to note that the function only calculates the number of weeks from the specified date in the same year.  If we used “3/15/2016” in the WEEKNUM function, the result would be the number of weeks from January 1st, 2016, which is 12.  The week starts on Sunday, so the same date might have a different week number result from year to year.

One drawback of the WEEKNUM function is that we are stuck with January 1st (system 1) or the week containing the first Thursday of the year (system 2).  It would be great if there was a 3rd argument that allowed us to specify the day of the year to start on.  This would be helpful for fiscal year calendars.  Unfortunately, we don’t have that feature yet.

Check out my article on how the calendar date system works in Excel for more details on how dates are stored as numbers.

#2 – Calculate the Number of Weeks Between Dates

To determine how many weeks elapsed between two dates, we can use a simple formula to find the number of days between the dates, then divide by 7.

=(B2-A2)/7

The formula will return a decimal number. We can change the number format to a Fraction to display the number of days.

Change Number Format for Week Number WEEKNUM to Fraction

Or, we can use one of the ROUND functions to ROUND UP or ROUND DOWN to the nearest whole number.

Round functions to round to nearest week number in Excel

This formula can also be used to countdown the number of weeks until your next birthday, vacation, holiday, quarter-end, year-end, etc.  We can use the TODAY() function to return today’s date in a cell.  The date will be updated with the current date every time we open or calculate the workbook.

TODAY Function to Return Current Date for Countdown in Week Numbers

#3 – Display the word “Week” in the Number Format

We might want to display the word “Week” before the week number in the cell.  There are a few ways to do this in Excel.  My preferred method is to use a custom number format to add the word “Week” before the week number.

Custom Number format to Display the word Week before the week number

The custom number format is:

"Week" #

The advantage of the custom number format is that the number remains a number, instead of text.  This makes it easier to sort by week number in filtered ranges and pivot tables.

Sorting Week Numbers with Custom Number Format

If the number is stored as text, it will not sort properly unless we use two digits for the week number.

Week Number stored as text does not sort properly

Therefore, I recommend using the custom number format to keep the data type of the cells as numbers.  This also helps keep the sort order when we create slicers on the Week Number field with the custom number format.

Custom Number Format keeps Sort Order in Pivot Tables and Slicers

I also have an article on 3 ways to display the weekday name of a date.

Other Methods for Calculating Week Numbers?

I hope you enjoyed those tips for working with week numbers in Excel.  These can be very useful for summary reports and week-over-week analysis.

Here are some related articles on working with dates in Excel.

  • How Dates Work in Excel: The Calendar System Explained + Video
  • Filter a Pivot Table or Slicer for the Most Recent Date or Period
  • Grouping Dates in a Pivot Table VERSUS Grouping Dates in the Source Data
  • How to Create Month to Date (MTD) Comparisons with a Pivot Table + Video
  • 3 Ways to Get the Day Name for a Date

What did I miss?  Do you have any additional tips for working with weeks?  If so, please leave a comment below with any suggestions or questions.

Well, I’m off to change a diaper and take a nap…  Thank you! 🙂

Week Number in Excel (WEEKNUM)

Week Number (WEEKNUM) is a DATE function in Excel that gives us the week number for the given date in a date. It has two arguments: one which takes a date as an argument which can be a date or a serial number. The other argument is optional, which represents the day on which the week begins. The second argument is optional; however, the first argument is mandatory. The method to use this WEEKNUM function is as follows: =WEEKNUM(serial_number,[return_type]). If the return type is not provided, Sunday is considered one by default.

For example, suppose cell A1 has July 8, 2021, which falls on Thursday. On applying the WEEKNUM Excel function, it will return 28.

=WEEKNUM(A1) 

=28.

Table of contents
  • Week Number in Excel (WEEKNUM)
    • Syntax
    • How to Use the Week Number (WEEKNUM) Function in Excel?
      • Example #1 – Finding Week Number in Excel
      • Example #2 – Add the Word WEEK to the Week Number in Excel
      • Example #3 – Calculate Number of Weeks in excel between Two Dates
      • Example #4 – Calculate the Number of Weeks in Fraction using Excel
    • Things to Remember
    • Recommended Articles

Syntax

WEEKNUM Formula in Excel

  • serial_number: This is the date. Based on this date, we are trying to find the week number of the date. Excel treats DATE as a serial number.
  • return_type: We need to mention the start of the weekday.

We have 10 different options to supply at the start of the week. Since this is an optional argument, we need not mandatorily supply the argument. However, if we leave this argument blank by default, the value will be 1, i.e., the start of the day of the week is Sunday.

The start of the year, Jan 01, will always be the first week of the year, and Dec 31 will always be the last week of the year, the 54th week.

How to Use the Week Number (WEEKNUM) Function in Excel?

You can download this WEEKNUM Function Excel Template here – WEEKNUM Function Excel Template

Example #1 – Finding Week Number in Excel

Assume you have the below dates. And you need to find the week number in Excel for each date in that particular year.
WEEKNUM Example 1

  1. Open the Excel WEEKNUM function in the B2 cell.

    WEEKNUM Example 1-1

  2. The serial_number is nothing but your date cell. So select A2 as the cell reference.

    WEEKNUM Example 1-2

  3. As of now, ignore the last argument. It will default consider Sunday as the starting day of the week.

    WEEKNUM Example 1-3

  4. Drag the formula to other cells.

    WEEKNUM Example 1-4

  5. We got week numbers for respective dates. But look at the cells A2 and A3; both are on 30th Nov but of a different year. Since Excel considers the start of the week from Sunday, it will vary year to year.

    WEEKNUM Example 1-9

  6. Now, let us change the start of the week to MONDAY.

    WEEKNUM Example 1-5

  7. You can mention the argument as 2. Close the formula.

    WEEKNUM Example 1-6

    The result is shown below:

    WEEKNUM Example 1-7

    Apply to other cells.

    WEEKNUM Example 1-8

    We do not see any differences here. Try changing the starting day of the week to a different date and find the differences.

Example #2 – Add the Word WEEK to the Week Number in Excel

We have seen how to return the week number of any supplied date. It will be cool to add the word “Week” before the week’s number, like in the image below.

WEEKNUM Example 2

It is where the advanced formatting technique in excelFormatting is a useful feature in Excel that allows you to change the appearance of the data in a worksheet. Formatting can be done in a variety of ways. For example, we can use the styles and format tab on the home tab to change the font of a cell or a table.read more comes into the picture. Follow the below steps to apply the above formatting.

  • Step 1: Select all the result cells first.

WEEKNUM Example 2

  • Step 2: Right-click on the selected cells and select “Format Cells.” You can directly press the shortcut key “Ctrl + 1.”

WEEKNUM Example 2-1.1

  • Step 3: Now, we will see below format dialog box. Go to “Custom” first.

WEEKNUM Example 2-1

  • Step 4: Enter the format code “Week” # in the Type: area.

WEEKNUM Example 2-2

  • Step 5: Press “OK.” We will have results ready.

WEEKNUM Example 2-3

Instead of changing the formatting of the cells, we can also combine the word “Week” with the result cells. Refer to the image to apply the same.

WEEKNUM Example 2-4

Example #3 – Calculate Number of Weeks in excel between Two Dates

We have learned the technique of finding the week number of the supplied technique in Excel. But, how do you tell how many weeks are between two dates?

Assume you started the project on 15th Jan 2018, and you completed the project on 30th April 2018. How do you tell how many weeks you had taken to complete the project?

WEEKNUM Example 3

  • Step 1: Firstly, find the difference between the two dates.

WEEKNUM Example 3-1

  • Step 2: Now, divide the difference by 7. We have 7 days a week.

WEEKNUM Example 3-2

  • Step 3: Press the “Enter” key to complete the formula. We have a result like this.

WEEKNUM Example 3-3

  • Step 4: Change the format to “General” for accurate results.

WEEKNUM Example 3-4

Example #4 – Calculate the Number of Weeks in Fraction using Excel

Let us consider one more example to have a clear idea about finding the week’s number between two dates in Excel.

You are going on a business trip from 15th Feb 2018. After all the duties are completed, you are coming back on 30th Jun 2018. Your business head decided to pay you the money weekly.

WEEKNUM Example 4

Now, you must tell me how many weeks you are going on a business trip. Let us apply the same formula we have used in the previous example.

Find the difference between two dates.

WEEKNUM Example 4-1

Now, divide the difference by 7. So we have 7 days a week.

WEEKNUM Example 4-2

We have a result like this.

WEEKNUM Example 4-3

Let us change the format of the resulting cell to fractions.

WEEKNUM Example 4-4

So, we have the number of weeks in fractions now.

WEEKNUM Example 4-5

Things to Remember

  • By default, the start of the week in Excel is SUNDAY.
  • We must supply the return type correctly if you want to start with a different week.
  • If the date is not in the correct format, we may get #VALUE! Error.

Recommended Articles

This article is a guide to WEEKNUM in Excel. We discuss finding week numbers in Excel using the WEEKNUM function, practical examples, and a downloadable Excel template. You may learn more about Excel from the following articles: –

  • Weekday in VBAWeekday in VBA is a date and time function to identify the weekday of a given date provided as an input. This function returns an integer value from 1 to 7 range. There is an optional argument provided to this function which is the first day of the week.read more
  • DATEDIF Function in Excel
  • EDATE Function in Excel
  • DATEVALUE in ExcelThe DATEVALUE function in Excel shows any given date in absolute format. This function takes an argument in the form of date text normally not represented by Excel as a date and converts it into a format that Excel can recognize as a date.read more

Part of Excel norms is working with numbers and dates because that is Excel’s forte. Where dates make the central part of the data, you may be working on them to add days, months, or years to them or to find the difference between them in days, months, and years.

We’ll walk you through counting the number of weeks between two dates today. By the end of this tutorial, you’ll learn counting whole weeks, nearest whole weeks, and weeks and days between dates, tied up together with a couple of Excel tricks.

Let’s get counting!

Count Weeks Between Dates in Excel

Counting Weeks Between Dates

Let’s learn first how we can calculate the number of weeks between two dates in Excel. We can then take things up a notch and calculate weeks and days between two dates.

Counting Whole Weeks

Let’s start with plain vanilla and get the add-ins to come in later. The first thing we are going to do is compute the difference in weeks between the dates with a bit of smoothing over using the INT function. The INT function rounds a number down to the nearest integer. Look at the formula below used on an example and we’ll show you why we would like to have the INT function to count weeks between dates:

=INT((D3-C3)/7)

We take the end date (in cell D3) first and subtract the start date (C3) from it. D3-C3 gives us the answer in days i.e. 14. D3-C3 is then divided by 7 so we get the answer in weeks instead and so, we arrive at 2.

This first instance was straightforward but if we look at C4 and D4, there is a difference of 20 days, and divided by 7, it gives 2.85714 and beyond. For such instances, we have the INT function ready in the formula to round the number down to the nearest whole number. Therefore, we get 2 as the result in the second instance even though it is closer to 3. This is because our objective is to count the complete weeks that have lapsed between the two dates.

Counting Whole Weeks

The numerically logical way of calculating the difference between dates is to subtract the earlier date from the later date because the other way around would incur a minus sign. That can be tackled with the ABS function, which ignores the sign of a number. Now if you were subtracting the later date from the earlier date, this would be the formula to use:

=ABS(ROUNDDOWN((C3-D3)/7,0))

As you can see, we haven’t just added the ABS function, but we’ve also replaced the INT function with the ROUNDDOWN function. ROUNDDOWN will round the outcome of C3-D3)/7 down and also requires the number of decimal places you want. Since we want an integer, ROUNDDOWN’s second argument is 0. The end date is being subtracted. Therefore, the integer will carry a minus sign. The ABS function returns the value without its sign.

Counting Whole Weeks

That is what is going on in the formula. Let us tell you why you can’t extend the INT formula while dealing with minus signs. INT rounds the number down to the nearest integer so if we are at -2.85, INT will round it down to -3. The ROUNDDOWN function rounds the number down toward 0. Hence, negative figures won’t be rounded down to the greater negative figure but would be rounded off close to 0 i.e. -2.

Nearest Whole Weeks

Previously we were counting the whole weeks between two dates. Now we’ll show you how to calculate the difference that is closer to the nearest whole number of weeks. Just a slight change in the formula from above should do it. Note the following formula:

=ROUND((D3-C3)/7,0)

Subtracting the dates, dividing them by 7, and maintaining that we don’t want any decimal places, the ROUND function rounds the number up or down to the closest digit and the mentioned number of digits. Looking at the results we can note in the second instance that 2.85 has been rounded up to 3 instead of 2.

Nearest Whole Weeks

Adding Text

How many times have you answered purely numerically in your math classes, to have the teacher ask you «5 what? 5 donkeys, 5 pizzas, 5 shoes?». Where the unit of measurement is embarrassingly important, here’s how to add the relevant text to the outcome. Use the following formula:

=INT((D3-C3)/7)&" weeks"

We’ve taken our first and plain vanilla formula of the day and extended it with the & operator and the text » weeks» enclosed in double quotes. Be sure to add the space before the text so you don’t get 2weeks in the result.

Adding Text

Happy teachers, happy days.

Note: The results of the formula have snapped from right alignment to left as they have become text values after adding text. Avoid adding text in the same cell if you want to further use the resulting value in calculations and number formulas.

Counting Weeks and Days Between Dates

Building up the formula, we’re not just going to aim to get the difference between the dates in weeks now but in weeks and days. For the «days» element, the MOD function will calculate the remaining days. The MOD function returns the remainder when two numbers are divided. This formula will return whole weeks and the remaining days:

=INT((D3-C3)/7)&" weeks "&MOD(D3-C3,7)&" days"

We’ll carry forward the last formula where we added text to the full weeks that passed between the dates in C3 and D3. Now to add the days, the & operator has concatenated the result of the MOD function. MOD subtracts C3 from D3 and the divisor is provided as 7; exactly like we have been doing with the INT formula i.e. D3-C3)/7. This expression gives us the whole weeks and the MOD function will give us the remainder of this expression, that is the remainder after the whole weeks.

C3 and D3 are exactly two weeks apart so we have 0 days in the first instance; » days» added as text after the MOD function with the & operator. Mind the right use of the space character in the text strings added in the formula. You may choose to add punctuation marks too such as the comma.

In the second instance, the gap between the dates is of 20 days the INT function returns 2 and the MOD function returns 6. That makes 2 weeks 6 days: spot on!

Counting Weeks and Days Between Dates

Adjustment for 0 Weeks

Just now you saw that C3 and D3 in our case example are giving us the difference of 2 weeks and 0 days, 0 days looking a bit odd if not a lot. Now with the plain vanilla going fully topped and loaded, we’re getting the last add-ons to the formula with the reuse of the MOD function and addition of the IF function. This formula should help you eliminate seeing 0 days in the result:

=INT((D3-C3)/7)&" weeks "&IF(MOD(D3-C3,7)=0,"",", "&MOD(D3-C3,7)&" days")

Advancing the formula from the previous section, we have added the IF function in the middle. The added bit reads that if the remainder of D3-C3 divided by 7 equals 0, then return an empty string (denoted by «»).

So the entire formula goes – number of weeks (computed by D3-C3/7), rounded down with the INT function, and suffixed with the text » weeks «. Then, if the remainder of the weeks calculation is 0, return empty text otherwise return the remainder of the weeks calculation and add » days» in text at the end.

Adjustment for 0 Weeks

Now you can see from the formula applied to the dataset; the number of weeks is only proceeded by the number of days if the latter doesn’t equal 0.

User Defined Function for Counting Weeks

We’re making our own formulas all the time so we’re going for the anomalous today; making our own function. Use VBA to create the function and apply it effortlessly. The function is similar to the DATEDIF function and you can find it in the steps below along with instructions to create the function:

  • Go to the Developer tab > Code group > Visual Basic icon or press the Alt + F11 keys to launch the Visual Basic

User Defined Function for Counting Weeks

  • Click on the Insert tab > Module option to open a Module

User Defined Function for Counting Weeks

  • Copy the code below and paste it in the Module
'Created by ExcelTrick.com
Function WeekDiff(date1 As Date, date2 As Date) As Long
WeekDiff = DateDiff("ww", date1, date2, vbMonday)
End Function

The syntax of the function is given in the first line of the code, date1 being the earlier date and date2 being the later date. In the second line, the third argument is set by us as vbMonday which will count Monday as the first day of the week.

By leaving the third argument out, the function will consider Sunday as the first weekday by default but if you want to change that as we did, when you enter the comma after date2 in line 2, an IntelliSense list will appear with a bubble comment regarding the syntax of the DateDiff function:

User Defined Function for Counting Weeks

  • Select your favored option by double-clicking it:

User Defined Function for Counting Weeks

  • Click on the Run button in the toolbar to run the code or press the F5

You will see a Macros dialog box appear when you run the code. Enter the name of the function (Weekdiff in this case) in the given field and select the Create button.

User Defined Function for Counting Weeks

  • Close the Visual Basic editor now that the function has been created.

Back to the worksheet, it looks like nothing has changed but when you head to the target cell to enter the formula, type the name of the created function and you will see a case-sensitive entry of the function in Excel’s IntelliSense.

User Defined Function for Counting Weeks

  • Select the function and enter the formula with the earlier date and then the later date.

User Defined Function for Counting Weeks

And you have the weeks between the dates with a created function! The number of weeks will lean towards the nearest whole figure.

Once you make good acquaintances with Excel, you’ll start finding out how little you must do on your own, which is always a good thing – especially in the Excel-verse. We hope you find the methods, tips, and tricks helpful for your task of counting weeks between dates. Keep adding to the plain vanilla as per your requirement. We’ll rope you in later with more of all that Excel jazz!

This post will teach you how to calculate days, weeks, months and years between two dates in excel. How do I count the number of days, weeks, months and years between 2 dates in excel.

Table of Contents

  • Calculate days between two dates
  • Calculate months between two dates
  • Calculate years between two dates
  • Calculate weeks between two dates
  • Calculate Years, Months and Days between two dates
    • Related Functions

If you want to calculate the difference in days between two dates, you can use the DATEDIF function to create an excel formula as follows:

=DATEIF(B1,B2, "D")

This formula will calculate days between two dates in cell B1 and B2, then returns the value in days.

Calculate months between two dates

If you want to calculate the difference in months between tow dates, you can also use the DATEDIF function to create the following generic formula:

=DATEDIF(B1,B2,"M")

You should note that the third argument is “M” in the DATEDIF function. So this formula returns the value in months between two dates in excel.

Calculate years between two dates

You can also use the DATEDIF function to calculate the number of years between two dates in excel, just refer to the following excel formula based on the DATEDIF function:

=DATEDIF(B1,B2,"Y")

This formula returns the value in years.

Calculate weeks between two dates

If you want to calculate the number of weeks between two dates, you just need to subtract start date from the end date and then the returned result is divided by 7. So you can write the below generic formula:

=(B2-B1)/7

calculate days weeks months between two dates1

This formula will return a decimal number, you can change the number format as you need.

Or you can use the INT function to rounds down to the nearest whole number or use ROUND function to round to nearest whole number.

=INT((B2-B1)/7)

calculate days weeks months between two dates2

=ROUND((B2-B1)/7,0)

calculate days weeks months between two dates3

You may be want to display the word “week” before the week number in the cell, you can do it as following steps:

1# right-click on the selected cells, then select Format Cells

2# on the Number Tab, choose Custom under Category, then select # “weeks” type.

calculate days weeks months between two dates4

calculate days weeks months between two dates5

Calculate Years, Months and Days between two dates

If you want to determine how many years, months and days between two dates, you can use the DATEDIF function to create the following complex formula:

=DATEDIF(B1,B2,"Y") & " Years, " & DATEDIF(B1,B2,"YM") & " Months, " & DATEDIF(B1,B2,"MD") & " Days"

If you do not want to use the DATEDIF function, and you can also use the following formula to achieve the same result:

=INT((TODAY()-A1)/365.25) & ” years , ” & INT(MOD((TODAY()-A1)/365.25,1)*12) & ” months and ” & INT(MOD((TODAY()-A1)/30.4375,1)*30.4375) & ” days”

  • Excel INT function
    The Excel INT function returns the integer portion of a given number. And it will rounds a given number down to the nearest integer.The syntax of the INT function is as below:= INT (number)…
  • Excel DATEDIF function
    The Excel DATEDIF function returns the number of days, months, or years between tow dates.The syntax of the DATEDIF function is as below:=DATEDIF (start_date,end_date,unit)…
  • Excel TODAY function
    The Excel TODAY function returns the serial number of the current date. So you can get the current system date from the TODAY function. The syntax of the TODAY function is as below:=TODAY()…
  • Excel Round function
    The Excel INT function rounds a number to a specified number of digits. You can use the ROUND function to round to the left or right of the decimal point in Excel.The syntax of the ROUND function is as below:=ROUND (number, num_digits)…

Summary

To get the week number from a date, you can use the WEEKNUM function. In the example shown, the formula in C5, copied down, is:

=WEEKNUM(B5)

Generic formula

Explanation 

The WEEKNUM function takes a date and returns a week number (1-54) that corresponds to the week of year. The WEEKNUM function starts counting with the week that contains January 1. WEEKNUM takes two arguments: a date, and (optionally) return_type, which controls the scheme used to calculate the week number. 

By default, the WEEKNUM function uses a scheme where week 1 begins on January 1, and week 2 begins on the next Sunday (when the return_type argument is omitted, or supplied as 1). With a return_type of 2, week 1 begins on January 1, and week 2 begins on the next Monday. See the WEEKNUM page for more information.

ISO week number

ISO week numbers, start on the Monday of the first week in a year with a Thursday. This means that the first day of the year for ISO weeks is always a Monday in the period between Jan 29 and Jan 4. Starting with Excel 2010, you can generate an ISO week number using 21 as the return_type:

=WEEKNUM(date,21)

Starting in Excel 2013, there is a new function called ISOWEEKNUM.

For more details, see Ron de Bruin’s nice write-up on Excel week numbers.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi — I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.

Great site — amazingly clear but with a lot of depth in terms of the explanations.

Get Training

Quick, clean, and to the point training

Learn Excel with high quality video training. Our videos are quick, clean, and to the point, so you can learn Excel in less time, and easily review key topics when needed. Each video comes with its own practice worksheet.

View Paid Training & Bundles

Help us improve Exceljet

Понравилась статья? Поделить с друзьями:
  • Calculate vba excel что
  • C excel open путь к файлу
  • Calculate variance with excel
  • C builder ячейки excel
  • Calculate total in excel