Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference in minutes between 2 bigquery timestamp fields

How can I get the difference in minutes between 2 timestamp fields in google bigquery? The only function I know is Datediff which gives the difference in day

Thanks

like image 859
user3569267 Avatar asked May 16 '14 13:05

user3569267


People also ask

How do you find the difference between two timestamps?

If you'd like to calculate the difference between the timestamps in seconds, multiply the decimal difference in days by the number of seconds in a day, which equals 24 * 60 * 60 = 86400 , or the product of the number of hours in a day, the number of minutes in an hour, and the number of seconds in a minute.

What is the difference between datetime and timestamp in BigQuery?

Datetime type: comprises both calendar date and time. It does not store time zone information: YYYY-MM-DD HH:MM:SS (e.g. ). Timestamp type: comprises date, time, and time zone information.

What is the timestamp format in BigQuery?

The format is: YYYY-MM-DD HH:MM:SS (e.g. 2021-05-15 16:45:23). Timestamp type: Date, time, and time zone information are all included in timestamps. If no time zone is given, the format falls back to UTC.

How do you subtract dates in BigQuery?

Subtracting a unit Subtracting a specific amount of days, weeks, months, quarters, or years from a date can be done using the DATE_SUB function. The first argument takes a date and the second argument takes an interval, a numeric value, and a unit. The supported units (DATE_PART) are: Days: DAY.


1 Answers

Pentium10's answer works for Legacy SQL. If you're using Standard SQL you can use TIMESTAMP_DIFF and it will do the math for you:

TIMESTAMP_DIFF(timestamp_1, timestamp_2, MINUTE) 

https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#timestamp-functions

like image 84
Paul Bendevis Avatar answered Nov 08 '22 03:11

Paul Bendevis