Search code examples
dategoogle-sheetsdate-conversion

Convert 7 or 8 digit number to true date


I have a column full of dates in this format mmddyyyy and I was wondering if I could parse or convert it to mm/dd/yyyy. I tried selecting the entire row and then clicking on format -> number -> date but when I do this, a date such as 12082016 becomes 6/7/34979 which of course makes no sense at all. Any ideas on how to fix this?

Edit:

Examples:

 7072016   12/11/2021
 1202017    12/2/2017
10042016    10/4/2016
 9212016    8/12/2023

I changed the B to F as that is where the date column is. What is strange is that some of the values are correct

=date(right(B2, 4), left(B2, 2), mid(B2, 3, 2))

Solution

  • You have to account for both 7 and 8 digit numbers. Apparently, you lost some leading zeroes when importing your data.

    =date(right(right("0"&A2, 8), 4), left(right("0"&A2, 8), 2), mid(right("0"&A2, 8), 3, 2))
    ' or,
    =--replace(replace(right("0"&A2, 8), 5, 0, "/"), 3, 0, "/")
    

    Format the cells as mm/dd/yyy or however you wish; They are true dates now.

    enter image description here