## Converting a Date in Excel to Week, Bi-Week, Month, and More

Published by Tim Wilson on January 15, 2013 All posts from Tim Wilson

I often find myself getting data out of one system or another (or multiple systems, and then combining them) as “daily” data — a series of metrics by day for a sequence of days. Sometimes, I work with that data at a daily level, but, often, I want to roll the data up by week, by month, or by some other time period.

For instance, if I want to look at the data weekly, I’ll use either the last day of the week or the first day of the week and then use a formula in a new column to convert each actual day to the “week” in which it falls:

In the example above, 1/15/2013 is a Tuesday that falls in a week that ends on Saturday, 1/19/2013. The same holds true for Wednesday (1/16), Thursday (1/17), Friday (1/18), and Saturday (1/19). As soon as get to 1/20/2013 (Sunday), I’m in a new week — a week that ends on 1/26/2013. Make sense?

By adding this column, I can create a pivot table that can easily generate weekly data for whatever metrics are in the spreadsheet.

This approach works for a number of different ways you might need to roll up daily data, so I thought a post that walks through some of the more common ones and the formula to carry out each conversion was in order. I’ve put all of the examples in this post in a downloadable spreadsheet that you can check out and play around with.

### Day of Week

The WEEKDAY() function returns a number — 1, 2, 3, 4, 5, 6, or 7. But, what if you actually want the day of the week in plain English?

You can use the CHOOSE() function and hard code values. Or, you can make a separate table that maps a number to each weekday and use VLOOKUP to populate the values. I’m not going to discuss either of those approaches…because my preferred approach is to use the TEXT() function.

For the fully written out weekday (“\$A3″ is the cell with 1/15/2013 in it — you would just drag this formula down, or, if you’re using an Excel Table, it would autofill):

=TEXT(\$A3,”dddd”)

For the 3-letter weekday:

=TEXT(\$A3,”ddd”)

Easy-peasy, no?

Note: If you simply want the date to be displayed as the weekday, you don’t need a formula at all — you can simply change the cell formatting to a custom format of “dddd” (for the full weekday) or “ddd” (for the 3-letter weekday). If you do that, the display of the data will be as a weekday, but the underlying value will still be the actual date. This formula actually makes the value the weekday. Depending on what your needs are, one approach or the other will make more sense.

### Convert to “Week Of”

The example I started this post with is converting each day to be the day that ends the week or the day that starts the week. To do this, you can use the WEEKDAY() function. The easiest way to understand how this works out is to write out (or put in Excel) a series of dates and then write the numbers 1 through 7 as you go down the dates. The farther you go into a week, the bigger the WEEKDAY() value is. So, if you subtract the WEEKDAY() value from the actual date, you will get the same value 7 days in a row, at which point the value will “jump” seven days. Make sense (it’s confusing…until it’s not)?

So, to convert a date to be the Saturday of the week the date falls in, use this formula (the “+7″ just keeps the converted value from being the Saturday of the previous week):

=\$A3-WEEKDAY(\$A3)+7

It’s the same idea if you wanted to use the first day of the week, with the week defined as starting on Sunday:

=\$A3-WEEKDAY(\$A3)+1

Obviously, you can use this basic formula for whatever “week” criteria you want. You just have to either think about it really hard…or experiment until it’s doing what you want.

### Convert to Bi-Weekly Date

Sometimes, a company operates on a bi-weekly cycle in some ways. For instance, a lot of companies pay their employees every two weeks. WEEKDAY() doesn’t work for this, because it doesn’t tell you which of the two weeks a day falls into.

In this case, I use MOD(). This function is, basically, a “remainder” function, and its main use is to calculate the remainder when one number is divided by another (for instance, “=MOD(14,4)” returns “2″ because, when you divide 14 by 4, you get a remainder of 2).

Well, Excel dates are, under the hood, just numbers. You don’t really need to know exactly what number a date is (although you can change the cell formatting to “Number” when a date is displayed and you will see the number). But, if you think about it, if you divide a date by 14, it’s going to have a remainder between 1 and 13. Let’s say the remainder is “2.” So, what will the remainder be if you divide the next day by 14? It will be “3.” And so on until you get to 13, at which point the next day, if divided by 14, will have a remainder of 0. Hmmm. This seems like we’ve recreated the WEEKDAY() function used above…but with a 14-day long period instead of 7-day one, right? Exactly!

So, if we wanted to convert a date to be the Saturday at the end of the bi-week period, it would be one of these two formulas (depending on which Saturday is the cutoff and which is the mid-period point):

=\$A3-MOD(\$A3-1,14)+13

or

=\$A3-MOD(\$A3-8,14)+13

If you wanted to use the start of the period, with the week starting on Sunday, then it would be one of these two formulas:

=\$A3-MOD(\$A3-1,14)

or

=\$A3-MOD(\$A3-8,14)

Again, it takes some experimentation if you want to adjust to other dates, but the “14″ will not change as long as you’re working on bi-weekly periods.

### Convert to Bi-Monthly Date

Sometimes (again, company pay periods are a good example), rather than using a bi-weekly calendar, you want to use a bi-monthly calendar — every date from the 1st through the 14th should be converted to the first day of the month, and every day from the 15th through the end of the month should be coded as the 15th. To do this, we use the DATE() function with an IF() statement for the day value:

=DATE(YEAR(\$A3),MONTH(\$A3),IF(DAY(\$A3)<15,1,15))

We know the year is the YEAR() of the date being converted, and we know the month is the MONTH() of the date being converted. But, we need to look at the day of the month and check if it is less than 15. If it is, then we return a day value of “1,” and, otherwise, we return a day value of “15.”

### Convert to Monthly Date

Monthly is almost as common, if not moreso, than weekly. To convert to the first day of the month is a straightforward use of the DATE() function. We pull the year using the YEAR() function on the date we’re converting, the month using the MONTH() function on the date we’re converting, and then simply hard code the “day” as “1:”

=DATE(YEAR(\$A3),MONTH(\$A3),1)

But, what if we want to use the last day of the month? We can’t hard code the “day” value because that day could be 28, 29 (leap year), 30, or 31. Curse you, Gregorian calendar!!!

Well, actually, this isn’t all that complicated, either. Why? Because the last day of the month is always the day before the first day of the next monthHuh? That’s right. That’s how we get the last day of the month: we use the DATE() function to figure out the first day of the next month (by adding 1 to the MONTH() value)… and then subtract 1:

=DATE(YEAR(\$A3),MONTH(\$A3)+1,1)-1

How do you like them apples?! [idiom ref.]

As an interesting aside, it would be understandable if this formula broke for the month of December. In that case, you’re actually telling Excel to calculate a date where the month is “13.” Luckily, Excel figures out what you mean and winds up returning January 1 of the following year (from which the formula then subtracts one to return December 31st).

I’ve just scratched the surface with possible date conversions in this post. Hopefully, the different approaches I described will trigger an idea or two for your specific situation. But, if you’ve got one that is stumping you, leave a comment here and I’ll take a crack at it!

And, all of the examples here are included in this downloadable spreadsheet. You can change the “start date” in cell A3 and all of the subsequent dates will automatically update. Happy date converting!

Categorized under Excel

• http://juliencoquet.com/en/ Julien Coquet

Hi Tim,

unless you’re stuck with Excel 2003 which sucks at time/date support, look into the EOMONTH() funtion to directly compute the last day of month (works with Excel 2007 and later)

http://office.microsoft.com/en-001/excel-help/eomonth-HP005209076.aspx

Julien

• http://www.gilliganondata.com Tim Wilson

Thanks, Julien! EOMONTH() is officially in my repertoire, now! It looks like it requires the Analysis ToolPak be installed to work. Any self-respecting analyst is going to have that enabled, but it would affect the portability of spreadsheet a bit, wouldn’t it? Very handy!

Hi! I know this is kind of off topic but I was wondering if you knew
where I could find a captcha plugin for my comment
form? I’m using the same blog platform as yours and I’m having problems finding one?

Thanks a lot!

• Prashanth Raju

This is wonderful piece of information that helped me in creating my end of week metrics of the daily data my system was logging. Thank you friend.

• Trudy Smith

This is really useful. Thanks!
One question – how do I create Thursday – Wednesday weeks & bi-weeks?

• http://tim.webanalyticsdemystified.com/ Tim Wilson

Hi Trudy,

To do Thursday – Wednesday where the start of the week (Thursday) is the date used: =\$A3-WEEKDAY(\$A3-4)+1

To do this bi-weekly, depending on which week you want to be the first week, it would be either:

=\$A3-MOD(\$A3-5,14)

or

=\$A3-MOD(\$A3-12,14)

Does that work?

• Trudy Smith

Thank you! worked perfectly!!!!

• Rhys

I work on manufacturing month ends for weeks pattern 4-4-5. So in March the month end is the 5th April. I then have a list of invoice dates and want to return what financial month it is in, for example invoice date 4th April would return March, but one on the 6th April would return April. Help?

• http://tim.webanalyticsdemystified.com/ Tim Wilson

That’s a good one. Retail calendars tend to give me fits as well, as I don’t think Excel has any sort of native awareness there.

The brute force method would be a hidden tab (or xlVeryHidden tab) with a table that lists all dates and their respective financial month, and then use a VLOOKUP to get that information for each invoice.

You could also make that a 12-row table rather than a 365-row table by listing the *start* day for each fiscal month and the fiscal month that it applies to. Then, do a VLOOKUP from your invoice day without using the last optional parameter (or set it to TRUE — but that’s the default). Even though it won’t find an exact match, it should find the right month.

Make sense?

• Rhys

I was trying to avoid vlookups. In the end opted for converting the date to a number and then “=IF(AND([@[Numerical Date]]41731),”Mar”,[@Month])” then i thought when the problem arises again in June ad more criteria to the formula.

• http://tim.webanalyticsdemystified.com/ Tim Wilson

That makes sense. As you roll from year to year, though, you’ll need to update, right (which you’d need to do with the VLOOKUP approach, too — adding rows to the table). I wonder if you could figure out the numerical date of the first day of the year of the invoice and then have a series of nested IFs from that point that break out the monthly buckets? It would be a messy formula.

• Roy Burton

how would I create a simple spreadsheet for a full 12 month period with 31 days, where every month you must tabulate the number of interviews completed on a daily basis.

• http://tim.webanalyticsdemystified.com/ Tim Wilson

I’m not sure I understand the question. Can you provide more detail?

• Dr. Buchanan

I have a column vector of weekly dates that match weekly price changes and two additional column vectors of daily dates and prices that I want to contemporaneously match to the first column, deleting the daily observations that lie between. I have been painstakingly plodding through the daily column vectors (deleting and moving up the date and corresponding price to match the first column). There has to be an easier way? Can you recommend something? Thanks!

• http://tim.webanalyticsdemystified.com/ Tim Wilson

(I followed up with Dr. Buchanan offline, and the solution here was a VLOOKUP — not strictly germaine to the main content of this post, so not posting details here.)