Select from a timestamp column between now and n days ago
Consider, if you need to filter records based on x days or weeks before today. Example query Select all records which are 2 weeks old.
You can use
timestamp functions to achieve this:
SELECT t.* FROM `my-pj.my_dataset.sample_table` t WHERE register_date BETWEEN TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -150 DAY) AND CURRENT_TIMESTAMP()) LIMIT 10;
BigQuery has three data types for date/time values:
timestamp. These are not mutually interchangeable. The basic idea is:
Dateshave no time component and no timezone
Datetimeshave a time component and no timezone
Timestamphas both a time component and a timezone. In fact, it represents the value in UTC
Enjoy great content like this and a lot more !
Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds