Skip to content

bigfunctions > parse_date

parse_date

Call or Deploy parse_date ?

✅ You can call this parse_date bigfunction directly from your Google Cloud Project (no install required).

  • This parse_date function is deployed in bigfunctions GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error).
  • Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions --> Read Getting Started. This is particularly useful if you want to create private functions (for example calling your internal APIs).
  • For any question or difficulties, please read Getting Started.
  • Found a bug? Please raise an issue here

Public BigFunctions Datasets are like:

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...

Description

Signature

parse_date(date_string)

Description

Parse date with automatic format detection (inspired from Sebabrata BigQuery tutorial)

Examples

select bigfunctions.eu.parse_date('2021-01-20 ')
select bigfunctions.us.parse_date('2021-01-20 ')
select bigfunctions.europe_west1.parse_date('2021-01-20 ')
+--------------------+
| cleaned_date       |
+--------------------+
| date('2021-01-20') |
+--------------------+

select bigfunctions.eu.parse_date('2021-1-20 ')
select bigfunctions.us.parse_date('2021-1-20 ')
select bigfunctions.europe_west1.parse_date('2021-1-20 ')
+--------------------+
| cleaned_date       |
+--------------------+
| date('2021-01-20') |
+--------------------+

select bigfunctions.eu.parse_date('2021/01/20 ')
select bigfunctions.us.parse_date('2021/01/20 ')
select bigfunctions.europe_west1.parse_date('2021/01/20 ')
+--------------------+
| cleaned_date       |
+--------------------+
| date('2021-01-20') |
+--------------------+

select bigfunctions.eu.parse_date('2021/1/20 ')
select bigfunctions.us.parse_date('2021/1/20 ')
select bigfunctions.europe_west1.parse_date('2021/1/20 ')
+--------------------+
| cleaned_date       |
+--------------------+
| date('2021-01-20') |
+--------------------+

select bigfunctions.eu.parse_date('01/20/21')
select bigfunctions.us.parse_date('01/20/21')
select bigfunctions.europe_west1.parse_date('01/20/21')
+--------------------+
| cleaned_date       |
+--------------------+
| date('2021-01-20') |
+--------------------+

select bigfunctions.eu.parse_date('1/20/21')
select bigfunctions.us.parse_date('1/20/21')
select bigfunctions.europe_west1.parse_date('1/20/21')
+--------------------+
| cleaned_date       |
+--------------------+
| date('2021-01-20') |
+--------------------+

select bigfunctions.eu.parse_date('Wed Jan 20 21:47:00 2021')
select bigfunctions.us.parse_date('Wed Jan 20 21:47:00 2021')
select bigfunctions.europe_west1.parse_date('Wed Jan 20 21:47:00 2021')
+--------------------+
| cleaned_date       |
+--------------------+
| date('2021-01-20') |
+--------------------+

Use cases

You have a table containing date strings in various formats, and you need to standardize them into a consistent DATE type in BigQuery for analysis. The parse_date function can automatically detect and convert these different formats.

Scenario:

You're analyzing customer orders, and the order_date column contains date values, but they were entered using different formats due to various data sources or input methods:

order_id order_date
1 2023-10-26
2 10/27/2023
3 Oct 28, 2023
4 28/10/23
5 Fri Oct 29 08:00:00 2023

Query using parse_date:

SELECT
    order_id,
    bigfunctions.us.parse_date(order_date) AS standardized_order_date
FROM
    your_project.your_dataset.your_table;

(Replace bigfunctions.us with the appropriate dataset for your region.)

Result:

order_id standardized_order_date
1 2023-10-26
2 2023-10-27
3 2023-10-28
4 2023-10-28
5 2023-10-29

Now all your dates are in a standard DATE format, allowing you to perform date-based calculations, filtering, and aggregations consistently without having to manually handle the different formats. For example, you could then easily query for all orders placed in October:

SELECT
    *
FROM
    your_project.your_dataset.your_table
WHERE
    standardized_order_date BETWEEN '2023-10-01' AND '2023-10-31';