Convert text and numbers to date and time

You can convert text and numeric fields in your data source into valid Date or Date & Time fields in Data Studio using calculated fields. This helps you parse ambiguous date formats so you can accurately sort, filter, and visualize time-based data in your reports.

Sometimes, though, the data is ambiguous, making it difficult for Data Studio to know how to handle it. For example:

  • 20201210 could represent a number or currency value: $20,201,210.
  • 12/10/2020 could represent Dec 10, 2020 or Oct 12, 2020.

Can't convert to date

If you connect to data that contains ambiguous dates or times, you may see a message saying "Data Studio can't convert [field] to a date". To resolve this, do one of the following:

Change the underlying data

If you can edit the dataset, consider changing the format of your date field to a full year, month, and day format. You may also be able to set the field's data type to date or date and time. This is the recommended approach, especially if you'll be creating multiple data sources from this dataset.

Convert to date using a calculated field

To create a valid Date or Date & Time field from your original unrecognized field, create a new calculated field and use the PARSE_DATE or PARSE_DATETIME function. See the following examples, replacing field with the name of the original (unrecognized) field.

Example formulas

Following are examples of how to convert text fields to Date fields:

Format Formula
2020-03-18 PARSE_DATE("%Y-%m-%d", field)
2020/03/18 PARSE_DATE("%Y/%m/%d", field)
20200318 PARSE_DATE("%Y%m%d", field)
3/18/2020 PARSE_DATE("%m/%d/%Y", field)
18/3/2020 PARSE_DATE("%d/%m/%Y", field)
Mar 18, 2020 PARSE_DATE("%b %d, %Y", field)
Wed, Mar 18, 2020 PARSE_DATE("%a, %b %d, %Y", field)
March 18, 2020 PARSE_DATE("%B %d, %Y", field)
Wednesday, March 18, 2020 PARSE_DATE("%A, %B %d, %Y", field)

Following are examples of how to convert text fields to Date & Time fields:

Format Formula
2020-03-18 16:45:00.000000 PARSE_DATETIME("%Y-%m-%d %H:%M:%E*S", field)
2020-03-18T16:45:00.000000 PARSE_DATETIME("%Y-%m-%dT%H:%M:%E*S", field)

Following is an example of how to convert a numeric field to a Date field:

Format Formula
20200318 PARSE_DATE("%Y%m%d", CAST(field AS TEXT))