Home > Software engineering >  Conditions in Excel: skip cells with dates without a year
Conditions in Excel: skip cells with dates without a year

Time:01-18

I have the results of a survey with birthdays in various date formattings.

  • 01.01.1990
  • 02/03
  • 04.05 etc.

Every time Excel sees a day and a month without a year it implies the current year and puts it in the cell without any hesitation. So, when we try to extract a year, we get not the error we expected but the current year, which is nonsense.

How can we avoid this behaviour?

The desireable result is:

  1. One column with one formula
  2. If the year is written, we extract it using =YEAR()
  3. If it is absent, we just do anything else, for instanse put "".

Basic change of formatting doesn't change the implication of the current year. And if we change the format of the whole column from date to text, we cannot use the formula "YEAR" anymore to any of the cells.

This is a task for students who can deal with Excel and Google Sheets only, Python is not an option.

I would be very grateful for any help!

CodePudding user response:

Both Excel and Google Sheets stores date as a number (day count) starting from 1900/01/01 so it either assumes year for you or doesn't recognize it as date at all. If you convert date to number, 1900/01/01 will be 1, 2023/01/16 will be 44942 (as it is 44942 day counting from 1900/01/01).

I assume that survey can't be filled by people born this year so just "filter" them out:

If date is in A1 use formula:

=IF(OR(YEAR(A1)=2023,YEAR(A1)=1900),"",YEAR(A1))

This will print nothing if captured year is 2023 or 1900 (this behavior also possible when dealing with dates without years).

  • Related