简体   繁体   中英

Excel: How to ask if the date in the cell is the current year and month?

I have a column (for example from A1 to A10) with dates. The structure is always the same ->
Cell A1 = 2019-02-01 till 2021-10-23 -> See the following Example

If the actual month and year ( today is october 2020) is equal to the second date entry of A1 (2021-10-23) the font color of cell A1 should be red.

How can I do this?
Thank you in advance.

You can ask for the date of today, using TODAY() or NOW() function. There also are the functions Year() and Month() to find the year and month number of a date. Combining all those should solve your question.

Changing formatting based on the content of a cell is easily done via conditional formatting. Pick your top cell, add a conditional formatting (start ribbon), pick new rule and pick the last one, based on formula.

If the structure is always exactly the same, you could find the last date using functions like LEFT() or MID() I'm not great with those, and had some problems matching text with dates, and had to use TEXT() . There's probably a nicer way to write it, but I ended up with something like this;
if A1 contained 2019-02-01 till 2020-10-23

=AND(MID(A1;17;4)=TEXT(YEAR(TODAY());"#");MID(A1;22;2)=TEXT(MONTH(TODAY());"#")

And then pick a formatting to apply with the formula returns true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM