Excel date sorting issue

%3CLINGO-SUB%20id%3D%22lingo-sub-2218048%22%20slang%3D%22en-US%22%3EExcel%20date%20sorting%20issue%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2218048%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20mix%20date%20data%20in%20the%20same%20column%3B%20yyyy-mm-dd%2C%20and%20yyyy-mm%2C%20and%20yyyy%20.%3C%2FP%3E%3CP%3EI%20need%20to%20sort%20it%20for%20my%20research.%26nbsp%3B%20yyyy-mm-dd%20date%20formats%20sort%2C%20BUT%20the%26nbsp%3Byyyy-mm%2C%20and%20yyyy%20do%20not%20sort%20within%20yyyy-mm-dd%20list.%3C%2FP%3E%3CP%3EI%20am%20using%20the%20English%20UK%20date%20style%2C%20and%20have%20tried%20creating%20%22custom%22%20formats%2C%20as%20well%20as%20different%20excel%20formats%2C%20but%20I%20cannot%20get%20this%20to%20work.%3C%2FP%3E%3CP%3EI%20need%20to%20keep%20year-month(if)-date(if)%20display%26nbsp%3B.%3C%2FP%3E%3CP%3EAny%20ideas%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2218048%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
New Contributor

I have a mix date data in the same column; yyyy-mm-dd, and yyyy-mm, and yyyy .

I need to sort it for my research.  yyyy-mm-dd date formats sort, BUT the yyyy-mm, and yyyy do not sort within yyyy-mm-dd list.

I am using the English UK date style, and have tried creating "custom" formats, as well as different excel formats, but I cannot get this to work.

I need to keep year-month(if)-date(if) display .

Any ideas?

6 Replies

@BobW696 

dates in Excel are actually integer numbers starting from 01 Jan, 1990 as 1. For example  17 Mar 2021 is actually 44272.  Applying formats like yyyy-mm-dd,  yyyy-mm, or yyyy you only change visual representation of such numbers, it shall not affect sorting.

 

However, if you have texts as "2021-03-17" and "2021-03" they'll be the text, doesn't matter which format you apply to them, such formatting doesn't affect text value. They are always will be sorted as texts in alphabetical order.

 

Thus the question is what is your data actually, texts or numbers.

@BobW696 

 

Are the yyyy-mm-dd and yyyy-mm values text? If so, try the following.

Let's say the values are in A2 and down.

In another column, enter the following formula in row 2:

 

=IF(LEN(A2)=10,DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2)),IF(LEN(A2)=7,DATE(LEFT(A2,4),MID(A2,6,2),1),DATE(A2,1,1)))

 

Fill down.

Sort the entire range on the new column. You can hide the new column if you prefer.

thank. But how do I accomplish my goal of being able to sort the dates in order regardless of if they are Year, month, day or year, month or just year?
I understand that there will have to be some type of rule about where does it appear (for example, yyyy in a list of yyyy-mm-dd; beginning or end/)
Would making them text enable me to sort?

@BobW696 

If you have texts, not dates, that's how @Hans Vogelaar suggested

Thanks, will give it a try!