I would like a formula that would return true if a given date is in this week, for example:
Lets say Today() is 2/18/2020
I would want it to return true if the GivenDate() is anywhere between 2/16/2020 and 2/22/2020.
I would also like a formula for isNextWeek().
Assuming the expected date is in cell A1, get the previous Monday:
=TODAY()-WEEKDAY(TODAY(),2)+1
Get the coming Sunday:
=TODAY()-WEEKDAY(TODAY(),2)+7
You can change the +1 to +8 for the next Monday, and the +7 to +14 for the next Sunday. So in effect,
=IF(AND(A1>=(TODAY()-WEEKDAY(TODAY(),2)+1),A1<=(TODAY()-WEEKDAY(TODAY(),2)+7)),"YES","NO")
This will return YES if A1 is between Monday and Sunday of this week.
=IF(AND(A1>=(TODAY()-WEEKDAY(TODAY(),2)+8),A1<=(TODAY()-WEEKDAY(TODAY(),2)+14)),"YES","NO")
This will return YES if A1 is between Monday and Sunday of next week.
I'm certain this can be simplified.
For this week:
=AND(WEEKNUM(TODAY())=WEEKNUM(A1),YEAR(TODAY())=YEAR(A1))
For Next Week
=AND(WEEKNUM(TODAY())+1=WEEKNUM(A1),YEAR(TODAY())=YEAR(A1))
One note: This will fail during the new year change.
For a formula that works no matter if over the new year:
This Week:
=MEDIAN(TODAY()-WEEKDAY(TODAY())+1,TODAY()-WEEKDAY(TODAY())+7,A1)=A1
Next Week:
=MEDIAN(TODAY()-WEEKDAY(TODAY())+8,TODAY()-WEEKDAY(TODAY())+14,A1)=A1
Related
How can one return the next date of a given weekday (it could be either a number 1-7 or names Sunday-Saturday).
For example, if today, on Friday 16-Oct-2009 I passed in:
Friday, it would return today's date 16-Oct-2009
Saturday returns 17-Oct-2009
Thursday returns 22-Oct-2009
Here is the Spreadsheet
I have tried this formula:
=A12+(C12+ MOD(7-day(A12),7))
I worked out an answer to my own question
Here is the formula
=date(year(A12),month(A12), day(A12) + mod(C12+ 7-WEEKDAY(A12),7))
This worked for me:
=TODAY()+MOD(4 + 7-WEEKDAY(TODAY()),7)
Just replace TODAY() and 4 (weekday#) for your context.
This is the formula you are seeking.
=A12+(7-WEEKDAY(A12)+B12)
A12 holds the start date. B12 holds the ID of the targeted weekday, e.g. 1 for "Sunday".
A11 must hold a true date, as opposed to a text string that looks like a date. If the latter is the case an error will be displayed. The result is always a date. You can format that date as "dddd" to display a day's name or "dddd, dd-mm-yyyy" to display both date and day.
And here are the mechanics of the formula:- A12-WEEKDAY(A12) returns always the previous Saturday, a date that is always in the past. A12+(7-WEEKDAY(A12)) inverts that calculation, returning always the next Saturday. This date is always in the future except when A12 is a Saturday. That's when the result will be = A12.
Having found a stable base, you can just add the day you want to the Saturday you have. Add 1 (for Sunday) and you get a Sunday. Add 7 and you get a Saturday. All these dates will be in the future.
That's all as you want it except that if WEEKDAY(A12) = B12 you want the same date as in A12 which is a week earlier than the one the formula prefers. This is where I went wrong while in haste. My apologies! This is the correct modification of the formula's result, to wit, conditionally deduct 7 from the calculation.
=A12+(7-WEEKDAY(A12)+B12)-IF(WEEKDAY(A12)=B12,7,0)
I have a table and I have a date in cell B4 which is something like 15/03/2021
I want to count values where the start date is the value on cell B4 but also count everything till the end of that week. So everything from Monday 15/03/2021 to Sunday 21/03/2021
What I have so far is something like
=COUNTIFS(MySheet!A:A,"Y",MySheet!C:C,">="&B4)
My trouble is how to tell it "also count everything until sunday that week without having to manually put the end date into a cell
Add 6 to the value in B4 to get the second criteria.
=COUNTIFS(Mysheet!A:A,"Y",Mysheet!C:C,">="&B4, Mysheet!C:C,"<="&B4+6)
I assume the question behind your question is how to account for dates in B4 other than a monday and keep counting untill the end of that same week, therefor you can use:
=COUNTIFS(Mysheet!A:A,"Y",Mysheet!C:C,">="&B4,Mysheet!C:C,"<="&B4+7-WEEKDAY(B4,2))
This does set a Sunday as the "end" of the week as per your OP.
Your question is slightly ambiguous, so there are two possible answers
To count for exactly 7 days:
=COUNTIFS(MySheet!A:A,"Y", MySheet!C:C,">="&B4, MySheet!C:C,"<"&B4+7)
To count until the end of the next Sunday: (N.B. On Sundays, this will only count 1 day)
=COUNTIFS(MySheet!A:A,"Y", MySheet!C:C,">="&B4, MySheet!C:C,"<"&B4+8-Weekday(B4,2))
This works by saying "on or after (>=) the date given", and "before (<) 7 days later / the following Monday"
I'm using the following formulas to obtain the start date and end date of the week number, given the week number and the year:
Start of week:=MAX(DATE(A2,1,1),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+(B2-1)*7+1)
End of week: =MIN(DATE(A2+1,1,0),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+B2*7)
It seems to work well except that week 1 of 2019 begins on 31-12-2018 but my formula for the start date of the week 1 shows it as 01-01-2019. What is the problem with my formula?
Just subtract 6 from the end date formula
=(MIN(DATE(A2+1,1,0),DATE(A2,1,1)-WEEKDAY(DATE(A2,1,1),2)+B2*7))-6
As I noted in my comment, the easiest way is just to subtract 6 from your end date. If your data is in a table, your formula would be =[#EndDate]-6. Otherwise, it would be something like =E2-6.
This command line gives the last work day of the month (True or False). I don't know how to change the commands to get the first work day of each month. If we are assuming the entire column A is the Date. format is mm/dd/year
AND(WEEKDAY(A2,2)<6,MONTH(WORKDAY(A2,1))<>MONTH(A2))
The first day of the month is
date-DAY(date)+1
In your case:
A2-DAY(A2)+1
To check weather A2 is the first day of its month:
A2 = A2-Day(A2)+1
'Simplify equation
Day(A2) = 1
So as a result =(Day(A2)=1) evaluates to True/False
Regarding your formula weather a date is the last day of the month, that can be done by:
=(A2=EOMONTH(A2,0)
I believe this is what you're looking for
=DAY(A2)=1
I need an Excel formula that takes a given day and provides the next upcoming Thursday of that week. I have a list of dates with time stamp attached:
Date Week Ending
10/5/2015 10/8/2015
10/11/2015 10/15/2015
10/21/2015 10/22/2015
10/27/2015 10/29/2015
I want to convert it to the weekending. The example is of my date and the "Week Ending" I want the formula to show.
Assuming Date is in A1, if #Grade 'Eh' Bacon's solution is not working for you and given your mention of time stamp attached, maybe treat your dates as text and say, in B2 and copied down to suit:
=LEFT(A2,10)+(7-WEEKDAY(LEFT(A2,10),15))
Assuming your data is in A1, the formula is simply:
=A1+(7-WEEKDAY(A1,15))
Weekday(A1,15) gives the number of the day of the week of a given date, and the option ,15 says use a week starting with Fri and ending with Thurs. So, a given date, + (7-Weekday()) will give you the number of days required to get to the 'week ending with the Thursday on x date'.
If you want a Thursday to return the same date, then try:
=A1+7-WEEKDAY(A1+2)
The more generalized version would be:
=A1+7-WEEKDAY(A1+7-DOW)
where DOW (DayOfWeek) translates
Sun = 1
Mon = 2
...
Sat = 7