Does anyone know an excel formula in which if the dates are within this week (Todays date) for the cells to read the text “this week” and if the dates are from the last week for the cells to read “last week”.
Ps: If the formula could also read «old» if the date range is not with this week or last week
Example: Column A has the following dates. I want column b to read whether or not the date is within this week or last week from today’s date.
Column A | Column B |
---|---|
01/11/2013 | Old |
02/11/2013 | Old |
03/11/2013 | Old |
04/11/2013 | Old |
05/11/2013 | Old |
06/11/2013 | Old |
07/11/2013 | Old |
08/11/2013 | Old |
09/11/2013 | Old |
10/11/2013 | Old |
11/11/2013 | Old |
12/11/2013 | Old |
13/11/2013 | Old |
14/11/2013 | Last week |
15/11/2013 | Last week |
16/11/2013 | Last week |
17/11/2013 | Last week |
18/11/2013 | Last week |
19/11/2013 | Last week |
20/11/2013 | Last week |
21/11/2013 | This Week |
22/11/2013 | This Week |
23/11/2013 | This Week |
24/11/2013 | This Week |
25/11/2013 | This Week |
26/11/2013 | This Week |
27/11/2013 | This Week |
28/11/2013 | This Week |
Big thanks to anyone who can solve this please.
Mr. Polywhirl
40.4k12 gold badges82 silver badges129 bronze badges
asked Nov 28, 2013 at 12:39
2
Assuming first date in A2
try this formula in B2
copied down to give those results:
=IF(A2 < TODAY()-14, "Old", IF(A2 < TODAY()-7, "Last week", "This Week"))
….but as per my comment that puts 8 days in current week, is that right? If not then change both <
to <=
.
Mr. Polywhirl
40.4k12 gold badges82 silver badges129 bronze badges
answered Nov 28, 2013 at 13:16
barry houdinibarry houdini
45.5k8 gold badges63 silver badges80 bronze badges
1
Just check if the difference between the week numbers.
Diff | Output |
---|---|
= 0 | This week |
= 1 | Last week |
>= 2 | Old |
Excel formula :
=if( (WEEKNUM(now()) - WEEKNUM(A1)) < 0,
"Future",
if( (WEEKNUM(now()) - WEEKNUM(A1)) = 0,
"This Week",
if( (WEEKNUM(now()) - WEEKNUM(A1)) = 1,
"Last Week",
"Old"
)
)
)
Mr. Polywhirl
40.4k12 gold badges82 silver badges129 bronze badges
answered Nov 28, 2013 at 12:44
2
This post will guide you how to highlight cell if date is the current day or is in the current week or month in Excel. How do I highlight row if date is in current week or month with conditional formatting in Excel 2013/2016.
- Highlight Cell if Date is in Current Day/Week/Month
- Highlight Row if Date is in Current Day/Week/Month
Table of Contents
- Highlight Cell if Date is in Current Day/Week/Month
- Highlight Row if Date is in Current Day/Week/Month
- Related Functions
To highlight the cell of current day or the date is in the current week or month, you can do the following steps:
#1 select the range of cells that you want to highlight date.
#2 go to HOME tab, click Conditional Formatting command under Styles group, and click Highlight Cells Rules menu from the drop down menu list, then select A Date Occurring sub menu. And the A Date Occurring dialog will appear.
#3 if you want to highlight the current day, then select Today option from the first drop down list box in the A Date Occurring dialog box, then choose one color that you want to fill the cell in the second drop down list box. Click Ok button.
Note: if you want to highlight the cell if date is in the current week, just choose This Week option from the first drop down list box. And if you want to highlight the cell if date is in the current month, just choose This Month from the first drop down list box.
#4 you should notice that the current date has been highlighted.
Highlight Row if Date is in Current Day/Week/Month
If you want to highlight the row that If the date in that row is equal to the current day or is in the current week or month, you can do the following steps:
#1 select the entire rows of data that contain date values.
#2 go to HOME tab, click Conditional Formatting command under Styles group, Click New Rule from the drop down menu list. And the New Formatting Rule dialog will open.
#3 click Use a formula to determine which cells to format option in the New Formatting Rule dialog box, type the following formula in the Format values where this formulas is true text box.
To highlight current date, use the following formula:
=$A2=TODAY()
To highlight row if date is in the current week, use the following formula:
=TODAY()-WEEKDAY(TODAY(), 3)=$A2-WEEKDAY($A2, 3)
To highlight row if date is in the current month, use the following formula:
=TEXT($A2,”mmyy”)=TEXT(TODAY(),”mmyy”)
Note: the Cell A2 is the first cell of your selected range.
#4 click Format button, and the Format Cells dialog will open. Click Fill tab, select on color that you want to use. Click Ok button.
#5 click Ok button. You should see that the entire rows which contain the current day have been highlighted.
- Excel WEEKDAY function
The Excel WEEKDAY function returns a integer value representing the day fo the week for a given Excel date and the value is range from 1 to 7.The syntax of the WEEKDAY function is as below:=WEEKDAY (serial_number,[return_type])… - 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 Text function
The Excel TEXT function converts a numeric value into text string with a specified format. The TEXT function is a build-in function in Microsoft Excel and it is categorized as a Text Function. The syntax of the TEXT function is as below: = TEXT (value, Format code)…
The IF function is one of the most useful Excel functions. It is used to test a condition and return one value if the condition is TRUE and another if it is FALSE.
One of the most common applications of the IF function involves the comparison of values.
These values can be numbers, text, or even dates. However, using the IF statement with date values is not as intuitive as it may seem.
In this tutorial, I will demonstrate some ways in which you can use the IF function with date values.
Syntax and Usage of the IF Function in Excel
The syntax for the IF function is as follows:
IF(logical_test, [value_if_true], [value_if_false])
Here,
- logical_test is the condition or criteria that you want the IF function to test. The result of this parameter is either TRUE or FALSE
- value_if_true is the value that you want the IF function to return if the logical_test evaluates to TRUE
- value_if_false is the value that you want the IF function to return if the logical_test evaluates to FALSE
For example, say you want to write a statement that will return the value “yes” if the value in cell reference A2 is equal to 10, and “no” if it’s anything but 10.
You can then use the following IF function for this scenario:
=IF(A2=10,"yes","no")
Comparing Dates in Excel (Using Operators)
Unlike numbers and strings, comparison operators, when used with dates, have a slightly different meaning.
Here are some of the comparison operators that you can use when comparing dates, along with what they mean:
Operator | What it Means When Using with Dates |
---|---|
< | Before the given date |
= | Same as the date with which we are comparing |
> | After the given date |
<= | Same as or before the given date |
>= | Same as or after the given date |
It may look like IF formulas for dates are the same as IF functions for numeric or text values, since they use the same comparison operators.
However, it’s not as simple as that.
Unfortunately, unlike other Excel functions, the IF function cannot recognize dates.
It interprets them as regular text values.
So you cannot use a logical test such as “>05/07/2021” in your IF function, as it will simply see the value “05/07/2021” as text.
Here are a few ways in which you can incorporate date values into your IF function’s logical_test parameter.
Using the IF Function with DATEVALUE Function
If you want to use a date in your IF function’s logical test, you can wrap the date in the DATEVALUE function.
This function converts a date in text format to a serial number that Excel can recognize as a date.
If you put a date within quotes, it is essentially a text or string value.
When you pass this as a parameter to the DATEVALUE function, it takes a look at the text inside the double quotes, identifies it as a date and then converts it to an actual Excel date value.
Let us say you have a date in cell A2, and you want cell B2 to display the value “done” if the date comes before or on the same date as “05/07/2021” and display “not done” otherwise.
You can use the IF function along with DATEVALUE in cell B2 as follows:
=IF(A2<DATEVALUE("05/07/2021"),"done","not done")
Here’s a screenshot to illustrate the effect of the above formula:
Using the IF Function with the TODAY Function
If you want to compare a date with the current date, you can use the IF function with the TODAY function in the logical test.
Let’s say you have a date in cell A2 and you want cell B2 to display the value “done” if it is a date before today’s date.
If not, you want let’s say you want to display the value “not done”. You can use the IF function along with the TODAY function in cell B2 as follows:
=IF(A2<TODAY(),"done","not done")
Here’s a screenshot to illustrate the effect of the above formula (assuming the current date is 05/08/2021):
Using the IF Function with Future or Past Dates
An interesting thing about dates in Excel is that you can perform addition and subtraction operations with them too.
This is because dates are basically stored in Excel as serial numbers, starting from the date Jan 1, 1900.
Each day after that is represented by one whole number.
So, the serial number 2 corresponds to Jan 2, 1900, and so on.
This means that adding n number of days to a date is equivalent to adding the value n to the serial number that the date represents.
If TODAY() is 05/07/2021, then TODAY()+5 is five days after today, or 05/12/2021. Similarly, TODAY()-3 is three days before today or 05/04/2021.
Let’s say you have a date in cell A2 and you want cell B2 to mark it as “within range” if it is within 15 days from the current date.
If not, you want to show “out of range”. You can use the IF function along with the TODAY function in cell B2 as follows:
=IF(A2<TODAY()+15,"within range","out of range")
Here’s a screenshot to illustrate the effect of the above formula (assuming the current date is 05/08/2021):
Points to Remember
Having discussed different ways to use dates with the IF function, here are some important points to remember:
- Instead of hardcoding the dates into the IF function’s logical test parameter, you can store the date in a separate cell and refer to it with a cell reference. For example, instead of typing =IF(A2<”05/07/2021”,”done”,”not done”), you can store the date 05/07/2021 in a cell, say B2 and type the formula: =IF(A2<B2,”done”,”not done”).
- Alternatively, you can use the DATEVALUE function as explained in the first part of this tutorial.
- Another neat technique that you can use is to simply add a zero to the date (which has been enclosed in double quotes). So you can type: =IF(A2<”05/07/2021”+0,”done”,”not done”). This will make Excel take the date inside double quotes as a serial number, and use it in the logical test without having its value changed.
In this tutorial, I showed you some great techniques to use the IF function with dates. I hope the tips covered here were useful for you.
Other articles you may also like:
- Multiple If Statements in Excel (Nested Ifs, AND/OR) with Examples
- How to use Excel If Statement with Multiple Conditions Range [AND/OR]
- How to Convert Month Number to Month Name in Excel
- Why are Dates Shown as Hashtags in Excel? Easy Fix!
- How to Convert Serial Numbers to Date in Excel
- How to Get the First Day Of The Month In Excel?
Skip to content
-
Check Also Extract Substring Between Parenthesis In Excel
-
Check Also Count Number Of Users Who Are Active In An Excel Workbook
-
Check Also VBA To Open Latest Excel Workbook
-
Check Also Print Cell Height And Cell Width Of A Cell In Excel
-
Check Also Delete Non Numeric Values From Numeric Field In Excel
-
Check Also Create Rows From Column In Excel
-
Check Also Sum Numbers Separated By Symbol In Excel
-
Check Also Sort Comma Separated Values Within A Cell In Excel
This post demonstrates how we could determine if a date falls in a given week.For planning purpose we are required to have such knowledge.
Let’s check in simple steps how we can check that a given date falls in a given week in excel.
Suppose we have a task start date, task end date and the week starting dates in columns and we are interested to have values as “Yes” or “No” depending on whether the task start and task end date falls under a given week as represented below.
The dates in row 2 are the week starting date.
Step 1
We will write a simple below formula using IF and OR function in excel.
=IF(OR(E$2<$B3,$C3<D$2),”No”,”Yes”)
D2 is the week starting date and E2 is the week ending date.
B2 is the task start date and C2 is the task end date.
Step 2
Now copy and paste the formula in the entire table as shown.
Hope this helped.
Random Posts
-
RGB And HSL In Excel
We could use customized color pellet in excel based on our RGB and HSL values. Some companies work with only […]
-
Highlight Mondays in Excel
Highlighting the days in excel is a frequent operation.We come across several situation in which we need to highlight some […]
-
-
Updated 12/16/22: Stay up to date on the latest from Excel and download Excel templates today.
Date functions in Microsoft Excel make it possible to perform date calculations, like addition or subtraction, resulting in automated or semi-automated worksheets. The NOW function, which calculates values based on the current date and time, is a great example of this.
Taking this functionality a step further, when you mix date functions with conditional formatting, you can create spreadsheets that display date alerts automatically when a deadline is near or differentiates between types of days, like weekends and weekdays.
Get a better picture of your data.
The basics of conditional formatting for dates
To find conditional formatting for dates, go to:
Home > Conditional Formatting > Highlight Cell Rules > A Date Occurring.
You can select the following date options, ranging from yesterday to next month:
These 10 date options generate rules based on the current date. If you need to create rules for other dates (e.g., greater than a month from the current date), you can create your own new rule.
Below are step-by-step instructions for a few of my favorite conditional formats for dates.
Highlighting weekends
When you design an automated calendar you don’t need to color the weekends yourself. With the conditional formatting tool, you can automatically change the colors of weekends by basing the format on the WEEKDAY function. Assume that you have the date table—a calendar without conditional formatting:
To change the color of the weekends, open the menu Conditional Formatting > New Rule.
In the next dialog box, select the menu Use a formula to determine which cell to format.
In the text box Format values where this formula is true, enter the following WEEKDAY formula to determine whether the cell is a Saturday (6) or Sunday (7):
=WEEKDAY(B$5,2)>5
Parameter 2 means Saturday = 6 and Sunday = 7. This parameter is very useful to test for weekends.
Note: In this case, you must lock the reference of the row so that the conditional format will work correctly in the other cells in this table.
Then, customize the format of your condition by clicking on the Format button and you choose a fill color (orange in this example).
format numbers as dates <br>or times in Excel
Learn more
Click OK, then open Conditional Formatting> Manage Rules.
Select This Worksheet to see the worksheet rules instead of the default selection. In Applies to, change the range that corresponds to your initial selection when creating your rules to extend it to the whole column.
Now you will see a different color for the weekends. Note: This example shows the result in the Excel Web App.
Highlighting holidays
To enrich the previous workbook, you could also color-code holidays. To do that, you need a column with the holidays you’d like to highlight in your workbook (but not necessarily in the same sheet). In our example, we have US public holidays in column AH (as related to the year in cell B2).
Again, open the menu Conditional Formatting > New Rule. In this case, we use the formula COUNTIF in order to count if the number of public holidays in the current month is greater than 1.
=COUNTIF($AH$4:$AH$16,B$5)>1
Then, in the dialog box Manage Rules, select the range B4:AF11. If you want to highlight the holidays over the weekends, you move the public holiday rule to the top of the list.
This example in the Excel Web App shows the result. Change the value of the month and the year to see how the calendar has a different format.
Highlighting delays
In case we want to change the color of cells based on our approach on a date again, we will use conditional formatting to make it work for us.
In the following example, we show:
- Yellow dates between 1 and 2 months.
- Orange dates between 2 and 3 months.
- Purple dates more than 3 months.
We then construct three rules of conditional formatting using the formula DATEDIF. Respectively for the three cases the following formulas:
=DATEDIF($B2,$E$2,”m”)>0
=DATEDIF($B2,$E$2,”m”)>1
=DATEDIF($B2,$E$2,”m”)>2
In the Excel Web App, try changing some dates to experiment with the result.
Task management in Microsoft 365
Collaborate on shared Office documents, including Excel, Word, and PowerPoint.
Color scales
Rather than choose a different color set for each period in our timeframe, we will work with the option of color scales to color our cells.
First, go into a new column (column E) and calculate the difference in the number of days in a year again with the DATEDIF formula and the parameter “yd”.
=DATEDIF($D2,TODAY(),”yd”)
Then choose the menu Conditional Formatting> New Rule option Format all cells based on their value and choose the following options:
- Scale = 3 colors
- Minimum = 0 Green
- Midpoint = 10 White
- Maximum = 30 Blue
The result is a gradient color scale with nuances from green to white and through blue. The closer to 0 the more green, the closer to 10 the more white, and the closer to 30 the more blue. In the Excel app, try changing some dates to experiment with the result.
Learn more
Explore Microsoft Excel today.
Additional resources:
- Read more about the DATE function.
- Read how to format numbers as dates and times.