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.*\nFROM `my-pj.my_dataset.sample_table` t\nWHERE register_date BETWEEN TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL -150 DAY) \nAND CURRENT_TIMESTAMP())\nLIMIT 10;\n
\n\nBigQuery has three data types for date/time values: date
, datetime
, and timestamp
. These are not mutually interchangeable. The basic idea is:
- \n
Dates
have no time component and no timezone \nDatetimes
have a time component and no timezone \nTimestamp
has both a time component and a timezone. In fact, it represents the value in UTC
dan-irving
posted onEnjoy 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
Post Comment