In data analysis, sometimes you may need to perform arithmetic on date columns, such as subtracting a number of days to obtain a past date. This guide will walk you through the process of subtracting days from a given date in Google BigQuery. This tutorial provides a clear understanding of date arithmetic in BigQuery, focusing on subtracting days.
Step 1: Setting up the table in BigQuery
We’ll set up a table named freshers_in_country_views that captures view counts by country on specific dates.
Step 2: Inserting sample data
For this example, let’s insert some sample data with various dates.
Step 3: Subtracting days from the date column
Assuming we want to find out the date 7 days before the recorded view_date, we can use the DATE_SUB function.
Output
BigQuery import urls to refer