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

# PostgreSQL JUSTIFY_HOURS() Function

**Info:** The `JUSTIFY_HOURS()` function works the same way across every PostgreSQL deployment, so you can apply what you learn here wherever you run Postgres. If you're an enterprise looking for managed Postgres built for the AI era, [Lakebase](https://www.databricks.com/product/lakebase) delivers a secure, high-performance database fully integrated with the Lakehouse. If you're a developer or startup who needs to ship and scale quickly, [Neon](https://neon.com) gives you the fastest path from idea to production on Postgres.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `JUSTIFY_HOURS()` function to adjust 24-hour intervals as days.

## Introduction to the PostgreSQL JUSTIFY_HOURS() function

The `JUSTIFY_HOURS()` function normalizes an [interval](../postgresql-tutorial/postgresql-interval) by converting hours exceeding 24 to days.

Here's the syntax of the `JUSTIFY_HOURS()` function:

```sql
JUSTIFY_HOURS ( value) → interval
```

In this syntax:

- `value` is an interval value you want to justify.

The `JUSTIFY_HOURS()` function returns an adjusted interval with:

- Hours exceeding 24 are converted to days.
- The remaining hours are kept the same.
- Minutes, seconds, and other units remain unchanged.

If the value is `NULL`, the function returns `NULL`.

## PostgreSQL JUSTIFY_HOURS() function examples

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

### 1) Basic PostgreSQL JUSTIFY_HOURS() function example

The following statement uses the `JUSTIFY_HOURS()` function to adjust intervals that are multiples of 24 hours:

```sql
SELECT JUSTIFY_HOURS(INTERVAL '24 hours'),
       JUSTIFY_HOURS(INTERVAL '48 hours'),
       JUSTIFY_HOURS(INTERVAL '72 hours');
```

Output:

```text
 justify_hours | justify_hours | justify_hours
---------------+---------------+---------------
 1 day         | 2 days        | 3 days

```

### 2) Using JUSTIFY_HOURS() function with intervals that are not multiple of 24 hours

The following example uses the `JUSTIFY_HOURS()` function to adjust intervals that are not multiples of 24 hours:

```sql
SELECT JUSTIFY_HOURS(INTERVAL '25 hours'),
       JUSTIFY_HOURS(INTERVAL '50 hours'),
       JUSTIFY_HOURS(INTERVAL '70 hours');
```

Output:

```text
 justify_hours  |  justify_hours  |  justify_hours
----------------+-----------------+-----------------
 1 day 01:00:00 | 2 days 02:00:00 | 2 days 22:00:00

```

### 3) Using the JUSTIFY_HOURS() function with intervals that include hours

The following example uses the `JUSTIFY_HOURS()` function to adjust intervals that include hours, minutes, and seconds:

```sql
SELECT JUSTIFY_HOURS(INTERVAL '15 days 2 hours'),
       JUSTIFY_HOURS(INTERVAL '55 days 30 minutes'),
       JUSTIFY_HOURS(INTERVAL '75 days 45 seconds');
```

Output:

```text
   justify_days   |      justify_days      |      justify_days
------------------+------------------------+-------------------------
 15 days 02:00:00 | 1 mon 25 days 00:30:00 | 2 mons 15 days 00:00:45
(1 row)
```

## Summary

- Use the `JUSTIFY_HOURS()` function to adjust 24-hour intervals as days.

---

## Related docs (Date Functions)

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