Saturday, April 14, 2018

Convert dates stored as text to dates

Convert dates stored as text to dates

Occasionally, dates may become formatted and stored in cells as text. For example, you may have entered a date in a cell that was formatted as text, or the data might have been imported or pasted from an external data source as text.

Dates that are formatted as text are left-aligned instead of right-aligned in a cell. With Error Checking turned on, text dates with two-digit years might also be marked with an error indicator Cell with a formula error .

Because Error Checking in Excel can identify text-formatted dates with two-digit years, you can use the automatic correction options to convert them to date-formatted dates. You can use the DATEVALUE function to convert most other types of text dates to dates.

Convert text dates with two-digit years by using Error Checking

If you import data into Excel from another source, or if you type dates with two-digit years into cells that were previously formatted as text, you may see a small green triangle in the upper-left corner of the cell. This error indicator tells you that the date is stored as text, as shown in this example.

Cells with green error indicator in upper-left corner

You can use the Error Indicator to convert dates from text to date format.

Notes: First things first- make sure Error Checking is enabled in Excel. To do that:

  1. Click File > Options > Formulas.

    In Excel 2007, click the Microsoft Office button Office button image > Excel Options > Formulas.

  2. Under Error Checking, check Enable background error checking. Any error that is found, will be marked with a triangle in the top-left corner of the cell.

  3. Under Error checking rules, select Cells containing years represented as 2 digits.

Follow the procedure below to convert the text-formatted date back to a regular date.

  1. On the worksheet, select any single cell or range of adjacent cells that has an error indicator in the upper-left corner.

    How to select cells, ranges, rows, or columns

    To select

    Do this

    A single cell

    Click the cell, or press the arrow keys to move to the cell.

    A range of cells

    Click the first cell in the range, and then drag to the last cell, or hold down Shift while you press the arrow keys to extend the selection.

    You can also select the first cell in the range, and then press F8 to extend the selection by using the arrow keys. To stop extending the selection, press F8 again.

    A large range of cells

    Click the first cell in the range, and then hold down Shift while you click the last cell in the range. You can scroll to make the last cell visible.

    All cells on a worksheet

    Click the Select All button.

    Select All button

    To select the entire worksheet, you can also press Ctrl+A.

    Note: If the worksheet contains data, Ctrl+A selects the current region. Pressing Ctrl+A a second time selects the entire worksheet.

    Nonadjacent cells or cell ranges

    Select the first cell or range of cells, and then hold down Ctrl while you select the other cells or ranges.

    You can also select the first cell or range of cells, and then press Shift+F8 to add another nonadjacent cell or range to the selection. To stop adding cells or ranges to the selection, press Shift+F8 again.

    Note: You cannot cancel the selection of a cell or range of cells in a nonadjacent selection without canceling the entire selection.

    An entire row or column

    Click the row or column heading.

    Worksheet headings

    1. Row heading

    2. Column heading

    You can also select cells in a row or column by selecting the first cell and then pressing Ctrl+Shift+Arrow key (Right Arrow or Left Arrow for rows, Up Arrow or Down Arrow for columns).

    Note: If the row or column contains data, Ctrl+Shift+Arrow key selects the row or column to the last used cell. Pressing Ctrl+Shift+Arrow key a second time selects the entire row or column.

    Adjacent rows or columns

    Drag across the row or column headings. Or select the first row or column; then hold down Shift while you select the last row or column.

    Nonadjacent rows or columns

    Click the column or row heading of the first row or column in your selection; then hold down Ctrl while you click the column or row headings of other rows or columns that you want to add to the selection.

    The first or last cell in a row or column

    Select a cell in the row or column, and then press Ctrl+Arrow key (Right Arrow or Left Arrow for rows, Up Arrow or Down Arrow for columns).

    The first or last cell on a worksheet or in a Microsoft Office Excel table

    Press Ctrl+Home to select the first cell on the worksheet or in an Excel list.

    Press Ctrl+End to select the last cell on the worksheet or in an Excel list that contains data or formatting.

    Cells to the last used cell on the worksheet (lower-right corner)

    Select the first cell, and then press Ctrl+Shift+End to extend the selection of cells to the last used cell on the worksheet (lower-right corner).

    Cells to the beginning of the worksheet

    Select the first cell, and then press Ctrl+Shift+Home to extend the selection of cells to the beginning of the worksheet.

    More or fewer cells than the active selection

    Hold down Shift while you click the last cell that you want to include in the new selection. The rectangular range between the active cell and the cell that you click becomes the new selection.

    Tip: To cancel a selection of cells, click any cell on the worksheet.

  2. Next to the selected cell or range of cells, click the error button that appears.

    Error button

  3. On the menu, click either Convert XX to 20XX or Convert XX to 19XX. (If you want to simply get rid of the error indicator without converting the number, click Ignore Error.)

    Commands for converting dates

    This action converts the text dates with two-digit years to standard dates with four-digit years.

    Converted dates

    Once you have converted the cells from text-formatted dates, you can change the way the dates appear in the cells by applying date formatting.

Top of Page

Convert text dates by using the DATEVALUE function

To convert a text date in a cell to a serial number, you use the DATEVALUE function. Then you copy the formula, select the cells that contain the text dates, and use Paste Special to apply a date format to them.

  1. Select a blank cell and verify that its number format is General.

    How to verify the number format

    1. On the Home tab, in the Number group, click the arrow next to the Number Format box, and then click General.

      Excel  Ribbon Image

  2. In the blank cell:

    1. Type =DATEVALUE(

    2. Click the cell that contains the text-formatted date that you want to convert.

    3. Type )

    4. Press ENTER.

      The DATEVALUE function returns the serial number of the date that is represented by the text date.

      What is a serial number?

      Excel stores dates as sequential serial numbers so that they can be used in calculations. By default, January 1, 1900, is serial number 1, and January 1, 2008, is serial number 39448 because it is 39,448 days after January 1, 1900.

  3. To copy the conversion formula into a range of contiguous cells, select the cell in which you typed the formula, and then drag the fill handle Fill handle across a range of empty cells that matches in size the range of cells that contain text dates.

    After you drag the fill handle, you should have a range of cells with serial numbers that corresponds to the range of cells that contain text dates.

  4. Select the cell or range of cells that contains the serial numbers, and then on the Home tab, in the Clipboard group, click Copy.

    Excel Ribbon Image

    Keyboard shortcut  You can also press CTRL+C.

  5. Select the cell or range of cells that contains the text dates, and then on the Home tab, in the Clipboard group, click the arrow below Paste, and then click Paste Special.

  6. In the Paste Special dialog box, under Paste, select Values, and then click OK.

  7. On the Home tab, click the Dialog Box Launcher next to Number.

    Dialog Box Launcher in Number group

  8. In the Category box, click Date, and then click the date format that you want in the Type list.

  9. To delete the serial numbers after all of the dates are converted successfully, select the cells that contain them, and then press DELETE.

Top of Page

Need more help?

You can always ask an expert in the Excel Tech Community, get support in the Answers community, or suggest a new feature or improvement on Excel User Voice.

No comments:

Post a Comment