The DATETIME_TRUNC function in BigQuery will truncate the datetime to the given date_part.
DATETIME_TRUNC(datetime_expression, date_part)
Where date_part can be any of the following:
Returns: DATETIME
SELECT
DATETIME_TRUNC(CAST('2021-01-01 02:44:00' AS DATETIME), MILLISECOND) AS month,
DATETIME_TRUNC(CAST('2021-01-01 02:44:00' AS DATETIME), MINUTE) AS minute,
DATETIME_TRUNC(CAST('2021-01-01 02:44:00' AS DATETIME), YEAR) AS year
DATETIME_TRUNC is very handy for aggregating your data by a particular date_part, like MONTH. See the example below to see how you can aggregate by MONTH:
SELECT
SUM(number) AS total,
DATETIME_TRUNC(date, MONTH) AS month
FROM
(
SELECT
CAST('2021-02-04 12:50:01' AS DATETIME) AS date,
3 AS number
UNION ALL
( SELECT
CAST('2021-02-14 00:42:41' AS DATETIME) AS date,
7 AS number)
UNION ALL
( SELECT
CAST('2021-01-04 17:01:00' AS DATETIME) AS date,
27 AS number)
) AS table_3
GROUP BY
month
Make sure you've included your DATETIME_TRUNC column in your GROUP BY!
You'll need to make sure you're using the right function for your data type. To use DATETIME_TRUNC, you must be working with a DATETIME, and not a DATE, TIMESTAMP, or TIME.
You can use CAST to change your other date types to DATETIME, or use one of the equivalent functions for other date types like DATE_TRUNC.