XL: Converting Dates from yy/mm/dd to mm/dd/yy Format

Last reviewed: December 18, 1996
Article ID: Q113616
The information in this article applies to:
  • Microsoft Excel for Windows, versions 4.0, 4.0a, 5.0, 5.0c
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Excel 97 for Windows

SUMMARY

Files imported from mainframes and other systems may contain dates in the format yy/mm/dd. These date formats are not recognized by Microsoft Excel and are imported as text strings.

WORKAROUNDS

Method 1: Convert text to columns

In Microsoft Excel versions 5.x, 7.0, and 97, the following steps convert the data to correctly formatted dates as serialized date numbers.

  1. Highlight all dates. On the Data menu, click Text To Columns. This opens dialog 1 of 3 of the Convert Text to Columns Wizard.

  2. In step 1, click Delimited for Original Data Type. Click Next.

  3. In step 2, click the Tab checkbox. Click Next.

  4. In step 3, click the Date option button. Click YMD in the list of date formats. Your original data will be overwritten unless you enter a new destination. (The default value is the first cell of the range that you highlighted in step 1 above. Click Finish.

Method 2: Use a formula

In any version of Microsoft Excel, to convert the date text to a serial number, enter the following formula in the worksheet:

   B2: =DATEVALUE(MID(A2,4,2)&"/"&RIGHT(A2,2)&"/"&LEFT(A2,2))

The above formula assumes that the date to be converted is in cell A2.

Method 3: Use a macro

Microsoft Excel 4.0 Macro Example:

Microsoft provides macro examples for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following macro converts the date, to a serial number. If the separator between the yy mm and dd values is not a forward slash (/), then modify the SEARCH statements within the macro, replacing all occurrences of the forward slash with the appropriate character.

A1: Convert_Date A2: =SEARCH("/",ACTIVE.CELL()) A3: year=MID(ACTIVE.CELL(),1,A2-1) A4: =SEARCH("/",ACTIVE.CELL(),A2+1) A5: month=MID(ACTIVE.CELL(),A2+1,A4-A2-1) A6: day=MID(ACTIVE.CELL(),A4+1,2) A7: =FORMULA(DATEVALUE(month&"/"&day&"/"&year)) A8: =SELECT("r[1]c") A9: =IF(ACTIVE.CELL()<>"",GOTO(A2),RETURN())

The above macro assumes the following:

  • All the dates are organized in one vertical column.
  • The active cell is the first date to be converted in the column.
  • There is an empty cell at the end of the column of dates.


KBCategory: kbusage kbmacro kbhowto
KBSubcategory: xlformula xlmhowto
Additional reference words: 4.00 5.00 5.00c 7.00 8.00 97 XL97


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 18, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.