I made a Google spreadsheet with a list of birth dates, anniversaries, etc. that I would like to sort by when they occur in the year, not when they first happened.
If you sort by the date normally, it will put the oldest year first.
I'm looking for a way to sort these only by the month and day, so I can get a quick view of what's coming up in what order.
So far, I attempted to make a formula referencing the date column that only shows the month part and the day part, like so:
=month(C2)&"-"&day(C2)
This almost works, except since the values are appearing as text and without a leading 0, it sorts Oct, Nov and Dec right after Jan (since they all start with 1 and are therefore "lower" than 2, 3, etc).
Anyone have a better way to sort this automatically or know a formula function to correct mine?
Simply adding the leading zero to single-digit months would be my way, but I'm open to other options.
Best Answer
Ultimately, you need to do what you already predicted: adding a leading zero. The
TEXT
function will make that happen like this:I've created a formula that takes on the complete column, filter for empty cells, brings together the
MONTH
andDAY
andSORT
s the lot.Formula
Explained
Here's a break-down description of the formula:
FILTER
function will filter for all rows that have something.MONTH
andDAY
functions will extract the respective values from the date.TEXT
function will convert the value from point 2 into a pre-formattedSTRING
.ARRAYFORMULA
function will apply all the above to the complete column (skipping the header).SORT
function will sort the result, given by theARRAYFORMULA
.The
SORT
function allows for sorting. If you do that via a column sort, the entry of theARRAYFORMULA
is taken into account as well and gets re-positioned, causing mayhem.Screenshot
Example
See example file I've created: sorting dates as text