> This page location: Date Functions > CLOCK_TIMESTAMP
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL CLOCK_TIMESTAMP() Function

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `CLOCK_TIMESTAMP()` function to return the current date and time.

## Introduction to the PostgreSQL CLOCK_TIMESTAMP() function

The `CLOCK_TIMESTAMP()` function returns the current date and time with a timezone.

Here's the basic syntax of the `CLOCK_TIMESTAMP()` function:

```sql
CLOCK_TIMESTAMP()
```

The `CLOCK_TIMESTAMP()` function has no parameters.

The `CLOCK_TIMESTAMP()` function returns the current date and time as a [timestamp with a timezone](https://neon.com/postgresql/postgresql-date-functions/postgresql-current_timestamp).

When you call the `CLOCK_TIMESTAMP()` function multiple times within a statement, you'll get different results.

## PostgreSQL CLOCK_TIMESTAMP() function examples

Let's take some examples of using the `CLOCK_TIMESTAMP()` function.

### 1) Basic CLOCK_TIMESTAMP() function example

The following example uses the `CLOCK_TIMESTAMP()` function to obtain the current date and time:

```sql
SELECT CLOCK_TIMESTAMP();
```

Output:

```text
        clock_timestamp
-------------------------------
 2024-03-20 14:49:07.875891-07
(1 row)
```

The result is a timestamp with a time zone.

### 2) Calling CLOCK_TIMESTAMP() function multiple times within a statement

The following example calls the `CLOCK_TIMESTAMP()` function multiple times within a statement:

```sql
SELECT
  clock_timestamp(),
  pg_sleep(3),
  clock_timestamp(),
  pg_sleep(3),
  clock_timestamp();
```

Output:

```
-[ RECORD 1 ]---+------------------------------
clock_timestamp | 2024-03-20 14:51:21.92144-07
pg_sleep        |
clock_timestamp | 2024-03-20 14:51:24.924244-07
pg_sleep        |
clock_timestamp | 2024-03-20 14:51:27.931263-07
```

The output shows that the `CLOCK_TIMESTAMP()` function returns the actual date and time between the calls within the same statement.

### 3) Using the CLOCK_TIMESTAMP() function to measure the execution time of a statement

First, [define a new function](../postgresql-plpgsql/postgresql-create-function) called `time_it` to measure the execution time of a statement:

```sql
CREATE OR REPLACE FUNCTION time_it(
    p_statement TEXT
) RETURNS NUMERIC AS $$
DECLARE
    start_time TIMESTAMP WITH TIME ZONE;
    end_time TIMESTAMP WITH TIME ZONE;
    execution_time NUMERIC; -- ms
BEGIN
    -- Capture start time
    start_time := CLOCK_TIMESTAMP();

    -- Execute the statement
    EXECUTE p_statement;

    -- Capture end time
    end_time := CLOCK_TIMESTAMP();

    -- Calculate execution time in milliseconds
    execution_time := EXTRACT(EPOCH FROM end_time - start_time) * 1000;

    RETURN execution_time;
END;
$$ LANGUAGE plpgsql;
```

Second, use the `time_it()` function to measure the execution time of the statement that uses the `pg_sleep()` function:

```sql
SELECT time_it('SELECT pg_sleep(1)');
```

Output:

```text
   time_it
-------------
 1007.731000
```

It takes about 1008 ms or 1s to complete.

## Summary

- Use the `CLOCK_TIMESTAMP()` function to return the current date and time.

---

## Related docs (Date Functions)

- [AGE](https://neon.com/postgresql/postgresql-date-functions/postgresql-age)
- [AT TIME ZONE Operator](https://neon.com/postgresql/postgresql-date-functions/postgresql-at-time-zone)
- [CURRENT_DATE](https://neon.com/postgresql/postgresql-date-functions/postgresql-current_date)
- [CURRENT_TIME](https://neon.com/postgresql/postgresql-date-functions/postgresql-current_time)
- [CURRENT_TIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-current_timestamp)
- [DATE_PART](https://neon.com/postgresql/postgresql-date-functions/postgresql-date_part)
- [DATE_TRUNC](https://neon.com/postgresql/postgresql-date-functions/postgresql-date_trunc)
- [EXTRACT](https://neon.com/postgresql/postgresql-date-functions/postgresql-extract)
- [ISFINITE](https://neon.com/postgresql/postgresql-date-functions/postgresql-isfinite)
- [JUSTIFY_DAYS](https://neon.com/postgresql/postgresql-date-functions/postgresql-justify_days)
- [JUSTIFY_HOURS](https://neon.com/postgresql/postgresql-date-functions/postgresql-justify_hours)
- [JUSTIFY_INTERVAL](https://neon.com/postgresql/postgresql-date-functions/postgresql-justify_interval)
- [LOCALTIME](https://neon.com/postgresql/postgresql-date-functions/postgresql-localtime)
- [LOCALTIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-localtimestamp)
- [MAKE_DATE](https://neon.com/postgresql/postgresql-date-functions/postgresql-make_date)
- [MAKE_INTERVAL](https://neon.com/postgresql/postgresql-date-functions/postgresql-make_interval)
- [MAKE_TIME](https://neon.com/postgresql/postgresql-date-functions/postgresql-make_time)
- [NOW](https://neon.com/postgresql/postgresql-date-functions/postgresql-now)
- [PG_SLEEP](https://neon.com/postgresql/postgresql-date-functions/postgresql-pg_sleep)
- [STATEMENT_TIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-statement_timestamp)
- [TIMEOFDAY](https://neon.com/postgresql/postgresql-date-functions/postgresql-timeofday)
- [TO_DATE](https://neon.com/postgresql/postgresql-date-functions/postgresql-to_date)
- [TO_TIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-to_timestamp)
