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
 
You could try this also. if the data is in starting from A1 and going down all the way, use this
Code:
=IF((A1+7-(WEEKDAY(A1,2)))+7=TODAY()+(7-WEEKDAY(TODAY(),2)),"Last Week","Not Last Week")
in B1 and copy down. Change the "A1" in formula if your range is starting from some other cell.
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You could try this also. if the data is in starting from A1 and going down all the way, use this
Code:
=IF((A1+7-(WEEKDAY(A1,2)))+7=TODAY()+(7-WEEKDAY(TODAY(),2)),"Last Week","Not Last Week")
in B1 and copy down. Change the "A1" in formula if your range is starting from some other cell.

Thanks for the input asad.

Both formulas does the job but the one you came up with is definitely shorter.
 
Upvote 0
Nielf,

Be careful with the shorten formula. I thought of a pretty much the similar formula but dismissed it cause it failed to get the year over correctly. Highly dependable on how you want handle the "broken weeks" in ayear over eg 4 days in week 53 and 3 days in week 1
 
Last edited:
Upvote 0
It does for me :)
Code:
21/12/2015Not Last Week
22/12/2015Not Last Week
23/12/2015Not Last Week
24/12/2015Not Last Week
25/12/2015Not Last Week
26/12/2015Not Last Week
27/12/2015Not Last Week
28/12/2015Last Week
29/12/2015Last Week
30/12/2015Last Week
31/12/2015Last Week
1/01/2016Last Week
2/01/2016Last Week
3/01/2016Last Week
4/01/2016Not Last Week
5/01/2016Not Last Week
6/01/2016Not Last Week
7/01/2016Not Last Week
8/01/2016Not Last Week
9/01/2016Not Last Week
10/01/2016Not Last Week
11/01/2016Not Last Week

the above has been compared to 10/01/2016.
 
Last edited:
Upvote 0
Asad,

Select 02/01/2016 as date for today; the weeknum will be 1 hence last week will be week 53. Your formula takes the 7 days back selecting week 53 and week 1. If that what's Nielf is aiming for , fine but as mentioned it all depends on how to handle the broken week.

NB: mine selects 52 and 53 which is fully correct either but haven't thought of a way to fix that.
 
Last edited:
Upvote 0
It does for me :)
Code:
21/12/2015Not Last Week
22/12/2015Not Last Week
23/12/2015Not Last Week
24/12/2015Not Last Week
25/12/2015Not Last Week
26/12/2015Not Last Week
27/12/2015Not Last Week
28/12/2015Last Week
29/12/2015Last Week
30/12/2015Last Week
31/12/2015Last Week
1/01/2016Last Week
2/01/2016Last Week
3/01/2016Last Week
4/01/2016Not Last Week
5/01/2016Not Last Week
6/01/2016Not Last Week
7/01/2016Not Last Week
8/01/2016Not Last Week
9/01/2016Not Last Week
10/01/2016Not Last Week
11/01/2016Not Last Week

the above has been compared to 10/01/2016.

asad, have you testet the formula for years that have 53 weeks, e.g. 2020?
 
Upvote 0
It worked for all the examples you asked for.
the thing is that my formula is not looking for week number. It actually finds out the last day for the last week and checks if the date in question has the last day of the week as same day or not.
 
Upvote 0

Forum statistics

Threads
1,223,641
Messages
6,173,506
Members
452,518
Latest member
SoerenB

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