Date range formula (last week)

nielf

Board Regular
Joined
Nov 13, 2012
Messages
69
I'm trying to come up with a TRUE/FALSE formula to check if a date is within last week. I thought this would be quite simple but that's not the case (at least for me).

I have come up with a formula that checks if today's date is within the current week and year - and that works perfectly fine using WEEKNUM and YEAR. I thought I might be able to use WEEKNUM -1 or something similar but that's doesn't seem possible when you are at the start or end of the year.

My week starts on a Monday and the year must also be taking into consideration.

I hope you can help.

Hn5zbmf.png
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi,

try this:

Book1
AB
145-6-2016FALSE
156-6-2016TRUE
167-6-2016TRUE
178-6-2016TRUE
189-6-2016TRUE
1910-6-2016TRUE
2011-6-2016TRUE
2112-6-2016TRUE
2213-6-2016FALSE
2314-6-2016FALSE
2415-6-2016FALSE
2516-6-2016FALSE
2617-6-2016FALSE
Sheet1
Cell Formulas
RangeFormula
B14=AND(YEAR(TODAY())=YEAR(A14),WEEKNUM(TODAY(),2)-WEEKNUM(A14,2)=1)
 
Last edited:
Upvote 0
Hi Joris,

Thank you very much. Your solution works like a charm. Will the formula also work when the week number changes from week 52 in 2016 to week 1 in 2017?
 
Upvote 0
Hi,

No, the formula will evaluate into FALSE if the year-number of week 1 (eg 2017) will differ from the year-number of week 52 (eg 2016);
If you want the formula to go over from year to year change it to this:


Book1
AB
14-6-2016FALSE
25-6-2016FALSE
36-6-2016TRUE
47-6-2016TRUE
58-6-2016TRUE
69-6-2016TRUE
710-6-2016TRUE
811-6-2016TRUE
912-6-2016TRUE
1013-6-2016FALSE
Sheet1
Cell Formulas
RangeFormula
B1=OR(WEEKNUM(TODAY(),2)-WEEKNUM(A1,2)=1,ABS(WEEKNUM(TODAY(),2)-WEEKNUM(A1,2))=52,ABS(WEEKNUM(TODAY(),2)-WEEKNUM(A1,2))=51)
 
Upvote 0
Thanks a lot Joris. It is really appreciated.

I can see that this formula will work for the next couple of years. But what happens in year 2020 which has 53 weeks?
 
Upvote 0
Hi,

Will still work cause there are 3 checks in the formula:
This part will result in TRUEif it's a regular week;
WEEKNUM(TODAY(),2)-WEEKNUM(A1,2)=1
This part will result in TRUE if the previous year had 53 weeks;
ABS(WEEKNUM(TODAY(),2)-WEEKNUM(A1,2))=52
and this part will result in TRUE if the previous year had 52 weeks;
ABS(WEEKNUM(TODAY(),2)-WEEKNUM(A1,2))=51


as it's an OR construction the formula will also work with a year with 53 weeks.
 
Upvote 0
Would it be possible to include YEAR in the formula they way you did in the first formula you came up with?

The formula is showing TRUE for dates within the same period for other years as well.

jmO1yC3.png
 
Upvote 0

Book1
AB
1FALSE
8896-6-2016TRUE
8907-6-2016TRUE
8918-6-2016TRUE
8929-6-2016TRUE
89310-6-2016TRUE
89411-6-2016TRUE
89512-6-2016TRUE
Sheet1
Cell Formulas
RangeFormula
B1=OR(AND(YEAR(TODAY())=YEAR(A1),WEEKNUM(TODAY(),2)-WEEKNUM(A1,2)=1),AND(YEAR(TODAY())-YEAR(A1)=1, OR(ABS(WEEKNUM(TODAY(),2)-WEEKNUM(A1,2))=52,ABS(WEEKNUM(TODAY(),2)-WEEKNUM(A1,2))=51)))
 
Upvote 0

Forum statistics

Threads
1,223,637
Messages
6,173,489
Members
452,515
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top