---
title: window_time function
description: Learn the syntax of the window\_time function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/window_time
---

# `window_time` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 12.2 LTS and above

Returns the inclusive end time of a time-window produced by the [window](https://docs.databricks.com/aws/en/sql/language-manual/functions/window.md) or [session\_window](https://docs.databricks.com/aws/en/sql/language-manual/functions/session_window.md) functions.

## Syntax

```
window_time(window)
```

## Arguments

* `window`: A `window` column generated by the [window](https://docs.databricks.com/aws/en/sql/language-manual/functions/window.md) function.

## Returns

A `TIMESTAMP` value with the inclusive endpoint of the window.
This is equivalent to `window.end - INTERVAL '0.000001' SECOND`

## Examples

```sql
> SELECT a, window.start as start, window.end as end, window_time(window), cnt
    FROM (SELECT a, window, count(*) as cnt
           FROM VALUES ('A1', '2021-01-01 00:00:00'),
                       ('A1', '2021-01-01 00:04:30'),
                       ('A1', '2021-01-01 00:06:00'),
                       ('A2', '2021-01-01 00:01:00') AS tab(a, b)
           GROUP by a, window(b, '5 MINUTES'))
    ORDER BY a, window.start;
  A1  2021-01-01 00:00:00  2021-01-01 00:05:00  2021-01-01 00:04:59.999999 2
  A1  2021-01-01 00:05:00  2021-01-01 00:10:00  2021-01-01 00:09:59.999999 1
  A2  2021-01-01 00:00:00  2021-01-01 00:05:00  2021-01-01 00:04:59.999999 1
```

## Related functions

* [`session_window` grouping expression](https://docs.databricks.com/aws/en/sql/language-manual/functions/session_window.md)
* [`window` grouping expression](https://docs.databricks.com/aws/en/sql/language-manual/functions/window.md)
