Excel

Up

Converting 'yyyy-mm-dd' to 'mm/dd/yyyy'

Suppose you have a textual column in you spread-sheet whose rows are either empty or which contain values that look like this yyyy-mm-dd, where yyyy is a four-digit year, mm is a two digit month, and dd is a two-digit day. Since these have been inserted as textual values and not true date numbers, you cannot just apply a format, yet you wish to convert the values in that column to look like this: mm/dd/yyyy. Here is one way to do it. I'm sure there are more...

First, insert an empty column next to the column you are working with by clicking on the column header just to the right of your column with dates. For the sake of argument, lets say the column you wish to convert is J. So click on column K and select Insert/Cells. Now you have an empty column K.

Lets also assume that the first row (A) contains labels, so the first row with data is row B. Click on cell K2 and enter this formula:

 
=IF(LEN(J2)=0,"",CONCATENATE(MID(J2,6,2),"/",RIGHT(J2,2),"/",LEFT(J2,4)))

After entering the formula, you should see either an empty cell in K2 (if J2 has no date in it) or else a date that is formatted the way that you want. All you need to do now is select the cells in column K starting with K2, all the way down to the last row, then select Edit/Fill/Down.

Now select Edit/Copy, then click on cell J2, and then select Edit/Paste Special..., and from the Paste Special dialog, choose the option Values and click OK. Now click the header in column K (the column you had previously inserted) and choose Edit/Delete.

Now save your changes and you are done.

As an exercise, I want you to pick apart the formula I gave you and figure out how it works. It's a very simple formula, but it gives you an example of the types of things you can do with Excel.


Page last modified on October 18, 2005, at 07:24 AM