bigquery timestamp to date code example
Example 1: string to date in BQ
def save_to_bq_table():<br />bq_client = bigquery.Client()<br /># Saving data to a intermediate table then export it to GCS<br />query = "##Query with millions of records results##"<br />job_config = bigquery.QueryJobConfig()<br /># Set the destination table<br />table_ref = bq_client.dataset(dataset_id).table('TableID')<br />job_config.destination = table_ref<br />job_config.allow_large_results = True<br /># Start the query, passing in the extra configuration.<br />query_job = bq_client.query(<br />query,<br />location='US', # Location must match that of the source table<br />job_config=job_config) # API request - starts the query<br />query_job.result() # Waits for the query to finish<br />
Example 2: convert google analytics dathourminute to time stamp? sql
SELECT DATETIME_ADD(PARSE_DATETIME('%Y%m%d', date), INTERVAL h.hour * 60 + h.minute minute) AS datetime