4.8/5
Home

Integrations

Plug Count neatly into your existing data infrastructure

For data teams

Collaborative, AI-driven data exploration and modelling

For product & growth

Faster access to the answers which matter

For leaders

Turning data into an engine of improvement

Pricing

Latest post

Meet the new Count Agent

Meet the new Count Agent

Docs

Guides, references, and API docs

Blog

Opinions, analysis, and the occasional uncomfortable truth about data.

Webinars

Join our experts for deep dives into data analytics and business intelligence

Gallery

Browse ready-to-use canvas templates and try them instantly

Sign in

Where to begin?

Start for free

Spin up a canvas and explore your data — a couple of clicks, no card.

Book a demo

See it live. Bring your questions — we’ll bring the answers.

Still not sure?

Send us a note — we’ll point you the right way.

Data to decisions, faster.

Compare

  • Count vs BI
  • Count vs Notebooks
  • Count vs Chatbots
  • Count vs Hex
  • Count vs Looker
  • Count vs Tableau
  • Count vs Thoughtspot

Learn

  • Blog
  • Webinars
  • SQL tutorials

Legal & security

  • Privacy Policy
  • Terms of Use
  • Cookies Policy
  • Trust Center
  • Security

Social

  • LinkedIn →
  • YouTube →
  • X →

Start with the hard question.

Ask Count anything — we’ll take you straight into a canvas.

Opens sign-up with your prompt ready for Count.

© 2026 Count Technologies Ltd. All rights reserved.

Careers →Book a Demo →
count

SQL Resources

Count is the best SQL IDE, wrapped up in the best data analysis tool, all inside the best BI platform.

ARRAY_AGG
Arrays Explained
Arrays Explained
CASE
CAST
COALESCE
CONCAT
COUNT [DISTINCT]
CURRENT_DATE
CURRENT_DATETIME
CURRENT_TIMESTAMP
DATETIME_DIFF
DATETIME_TRUNC
DATE_DIFF
DATE_TRUNC
Data Types
Dates and Times
EXTRACT
IF
MEDIAN
SUBSTR
String Functions Explained
TIMESTAMP_DIFF
TIMESTAMP_TRUNC
TIME_DIFF
DefinitionPractical InfoCommon QuestionsTroubleshooting Common ErrorsRelated Pages
TIME_TRUNC
UNNEST
Window Functions Explained
SQL Resources/BigQuery Standard SQL/TIME_DIFF

TIME_DIFF

TIME_DIFF function. Definition, syntax, examples and common errors using BigQuery Standard SQL. The TIME_DIFF function allows you to find the difference between 2 time objects.

ℹ️

See also DATE_DIFF, DATETIME_DIFF, or TIMESTAMP_DIFF

Definition

The TIME_DIFF function allows you to find the difference between 2 TIMEs in the specified part interval.

Where part can be any of the following:

TIME_DIFF(time_expression_a, time_expression_b, part)
  • MICROSECOND
  • MILLISECOND

Returns: INT64

first_timesecond_timedifference
15:30:0014:35:0055

Practical Info

  • If the first TIME is earlier than the second one then the output will be negative
  • Throws an error if the computation overflows the result type, such as if the difference in microseconds between the two TIME objects would overflow an INT64 value.

Common Questions

How to filter for the last n seconds?

A common SQL query WHERE clause is to just pull the data for the last n seconds. In this case, we can make use of TIME_DIFF and CURRENT_TIME:

SELECT
  TIME '15:30:00' AS first_time,
  TIME '14:35:00' AS second_time,
  TIME_DIFF(TIME '15:30:00' , TIME '14:35:00', MINUTE) AS difference
timeseconds_since
13:05:00-2336
13:05:00-2336
13:05:00-2336

Troubleshooting Common Errors

Argument 2 of TIME_DIFF has incorrect type: expected time found datetime.

This one is all too common. If you're using TIME, you'll need to make sure both of your TIMEs are indeed TIME data types, and not DATEs or DATETIMEs. It's usually easy enough to add a CAST(timestamp_col as TIME) to your function:

SELECT
  time,
  TIME_DIFF(CURRENT_TIME(), time, SECOND) AS seconds_since
FROM
  (
    SELECT
      TIME '13:05:00' AS time
    UNION ALL
(    SELECT
      TIME '13:05:00' AS time)
    UNION ALL
(    SELECT
      TIME '13:05:00' AS time)
  ) AS table_3
WHERE
  (TIME_DIFF(CURRENT_TIME(), time, SECOND) <= 30)

Related Pages

  • DATETIME_DIFF
  • Dates & Times in Standard SQL
TIME_DIFF(CAST('2020-01-01 03:22:01' as TIME),'03:04:00', HOUR) hours_diff

Got a CSV?
See it differently in <2 mins

Get started for FREEWatch our CEO do it