# datatype

<br />

## Usage

```
view: view_name {
  dimension: order_date {
    datatype: date
  }
}
```

|---|---|
| Hierarchy [View File](https://docs.cloud.google.com/looker/docs/reference/param-view) [`view`](https://docs.cloud.google.com/looker/docs/reference/param-view-view) [Field Type](https://docs.cloud.google.com/looker/docs/reference/param-field) `datatype` | Possible Field Types Dimension, Dimension Group, Filter, Measure <br /> Default Value `timestamp` Accepts One of several possible values <br /> |

## Definition

The `datatype` parameter lets you specify the type of time or date data in your database table that you are supplying to your [dimension](https://docs.cloud.google.com/looker/docs/reference/param-field-dimension), [dimension_group](https://docs.cloud.google.com/looker/docs/reference/param-field-dimension-group), [filter](https://docs.cloud.google.com/looker/docs/reference/param-field-filter), or [measure](https://docs.cloud.google.com/looker/docs/reference/param-measure-types) field. Matching the data type to your field can increase query performance.

For dimensions, filters, and measures that contain date or time data, and for dimension groups with [`type: time`](https://docs.cloud.google.com/looker/docs/reference/param-field-dimension-group#type_time), the `datatype` parameter applies to the [`sql`](https://docs.cloud.google.com/looker/docs/reference/param-field-sql) parameter of the dimension group.

For dimension groups with [`type: duration`](https://docs.cloud.google.com/looker/docs/reference/param-field-dimension-group#type_duration), the `datatype` parameter applies to both the [`sql_start`](https://docs.cloud.google.com/looker/docs/reference/param-field-dimension-group#sql_start) and [`sql_end`](https://docs.cloud.google.com/looker/docs/reference/param-field-dimension-group#sql_end) parameters, so be sure the `sql_start` and `sql_end` are both of the specified data type.

The `datatype` parameter accepts the following values:

- `epoch` - a SQL epoch field (i.e., an integer representing the number of seconds from the Unix epoch)
- `date` - a SQL date field (i.e., one that does not contain time of day information)
- `datetime` - a SQL datetime field
- `timestamp` - a SQL timestamp field
- `yyyymmdd` - a SQL field that contains an integer that represents a date of the form **YYYYMMDD**

The default value for `datatype` is `timestamp`.

## Example

Create a [`dimension_group`](https://docs.cloud.google.com/looker/docs/reference/param-field-dimension-group) for a date field. Set the `datatype:` to `date` to increase query performance.

    dimension_group: order_date
      type: time
      timeframes: [date, week, month, year]
      datatype: date
      sql: ${TABLE}.order_date