'how do we start timestamp from yesterday

I am using this line in where statement

event_timestamp > UNIX_MICROS(TIMESTAMP_SUB(CURRENT_TIMESTAMP, INTERVAL 28 DAY))

it gives me results from today until the last 28 days. But today's data is not complete so I want from yesterday until last 28 days.

I want something like

event_timestamp > UNIX_MICROS(TIMESTAMP_SUB((CURRENT_TIMESTAMP - 1), INTERVAL 28 DAY))

Can someone support? Thank you



Solution 1:[1]

You can write where statement with two condition

where event_timestamp > UNIX_MICROS(TIMESTAMP_SUB(CURRENT_TIMESTAMP, INTERVAL 28 DAY)) and event_timestamp < UNIX_MICROS(TIMESTAMP_TRUNC(current_timestamp,DAY))

TIMESTAMP_TRUNC will truncate the timestamp to start off today's timestamp. that is to 00:00 hrs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pkd