Solved

# Sort dates that have double zeroes in the month or day section

Posted on 2015-02-11
129 Views
In the attached XL sheet, I have a Date column that I want to sort by year. The problem is, for some of the dates, I don't know the exact day or monty, only the year, so I've put a double zero (00) placeholder in there for the days/months I'm not sure of. It needs to be exact so I can't put 01 or anything like that in there. When I do this, it does not sort correctly. Is there some way to maintain the double zeroes and have the sheet column sort correctly by year?

Thanks,
Sort-Date.xlsx
0
Question by:contrain

LVL 18

Expert Comment

day of month = 00 is not a valid date and the cell becomes a text entry.

I'd suggest you use a default of 01 (first of the month) and add a column next to it with a flag to indicate uncertainty over the exact date.

>It needs to be exact
It just can't be exact all the time you have unknowns in there.

I suppose the other thing you could do would be to use a =Year(yourdatecolumn) formula to get the year on its own, though you'd manually have to enter the year for the non-date 00 entries that you added. You could then sort on that Year column.
0

LVL 22

Assisted Solution

Flyster earned 250 total points
Here's a round about way. This formula is used to determine the year:

=VALUE(IF(ISTEXT(A2)=TRUE,RIGHT(A2,4),YEAR(A2)))

It can be done without the Value function as it did not sort like I thought. Basically what it does is look at your data to determine if it text or not. If it is, it uses the Right Function. If not then it uses Year. Do the same for Month and Day, using the appropriate functions:

=IF(ISTEXT(A2)=TRUE,LEFT(A2,2),MONTH(A2)) for month and
=VALUE(IF(ISTEXT(A2)=TRUE,MID(A2,4,2),DAY(A2))) for day.

Once that's done, copy all the data and then paste it special as values on another sheet. (See Sheet2 of attached.) You can now sort on that data.

Flyster
Sort-Date.xlsx
0

LVL 31

Expert Comment

Flyster - you don't need the =TRUE part of those formulas. The IF statement will deal with the TRUE and FALSE conditions.
0

LVL 31

Expert Comment

I have found that some of the text entries have a spare space character at the end.

I have tried incorporating the TRIM function with Flysters suggestions and it all goes horribly wrong.
0

LVL 31

Accepted Solution

Rob Henson earned 250 total points
Year - =IF(ISTEXT(\$A2),RIGHT(TRIM(\$A2),4),YEAR(\$A2))
Month - =IF(ISTEXT(\$A2),MID(TRIM(\$A2),4,2),MONTH(TRIM(\$A2)))
Day - =IF(ISTEXT(\$A2),LEFT(TRIM(\$A2),2),DAY(TRIM(\$A2)))

Don't need to copy and paste, can sort in place by year then month then day.

I think it was going wrong because I was putting a TRIM around the first A2 as well "ISTEXT(TRIM(\$A2))" and by forcing a function on what looks like a date, Excel was trying to convert to a date, incorrectly in places.

Thanks
Rob H
0

LVL 31

Expert Comment

Just noticed, Flyster's suggestions have assumed date format mm/dd/yyyy whereas I have assumed date format dd/mm/yyyy.

The cell format of sample data would suggest mm/dd/yyyy to be correct so my formulas should be:

Year - =IF(ISTEXT(\$A2),RIGHT(TRIM(\$A2),4),YEAR(\$A2))
Month - =IF(ISTEXT(\$A2),LEFT(TRIM(\$A2),2),MONTH(TRIM(\$A2)))
Day - =IF(ISTEXT(\$A2),MID(TRIM(\$A2),4,2),DAY(TRIM(\$A2)))

Thanks
Rob H
0

Author Closing Comment

I am accepting and giving points to 2 answers because each gave me what I wanted even though there were slight differences on the formulas used. Great answers both to a very difficult situation!
0

## Featured Post

### Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…