Convert a numeric column of dates into a date/time column

If a column of dates has a numeric data type, you can change the data type to date/time.

Suppose you have a numeric column of dates in YYYYMMDD format. In this format, the value 20150101 represents January 1, 2015. You want to convert the numeric column to a date/time column in MM/DD/YYYY format. There are two ways to do this: use Change Data Type and Format Column, or use the Calculator.

In the following examples, C1 has a numeric data type and contains dates in this format: YYYYMMDD. C2 is empty.

Use Change Data Type and Format Column to convert the data type

Use Change Data Type to change the data type of the column to text. Then use Format Column to change the data type to date/time and specify the date/time format.

  1. Click in the column and choose Data > Change Data Type.
  2. In Variables, enter the column.
  3. From Choose type, select Text. Click OK.
  4. Click in the column and choose Editor > Format Column.
  5. From Choose type, select Date.
  6. In Custom date format, type yyyymmdd. Click OK in each dialog box.
  7. Click in the column and choose Editor > Format Column.
  8. From Date display formats, select 01/23/2050. Click OK.

Use the Calculator to convert the data type

Using the Calculator, you can convert the data in one step. The result is stored in C2.

  1. Choose Calc > Calculator.
  2. In Store result in variable, enter C2.
  3. Copy and paste the following into Expression: DATE(CONCATENATE(MID(TEXT(C1),5,2),"/",RIGHT(TEXT(C1),2),"/",LEFT(TEXT(C1),4)))
  4. Click OK.
By using this site you agree to the use of cookies for analytics and personalized content.  Read our policy