BigQuery提供了一系列日期时间和时间戳函数,可以用于处理和转换日期时间数据。以下是一些常用的函数及其代码示例:
SELECT CURRENT_DATE() AS current_date;
SELECT CURRENT_DATETIME() AS current_datetime;
SELECT CURRENT_TIMESTAMP() AS current_timestamp;
SELECT EXTRACT(YEAR FROM timestamp_field) AS year,
EXTRACT(MONTH FROM timestamp_field) AS month,
EXTRACT(DAY FROM timestamp_field) AS day
FROM mytable;
SELECT DATE(timestamp_field) AS date
FROM mytable;
SELECT TIME(timestamp_field) AS time
FROM mytable;
SELECT TIMESTAMP(date_field, time_field) AS timestamp
FROM mytable;
SELECT DATE_ADD(date_field, INTERVAL 1 DAY) AS new_date
FROM mytable;
SELECT DATE_DIFF(date1, date2, DAY) AS date_difference
FROM mytable;
SELECT DATE_SUB(date_field, INTERVAL 1 WEEK) AS new_date
FROM mytable;
这些是一些常见的BigQuery日期时间和时间戳函数及其代码示例。根据具体的需求,还可以使用其他函数来处理日期时间数据。
上一篇:BigQuery日期间隔语法
下一篇:BigQuery日期需要多少字节