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

# PostgreSQL JUSTIFY_HOURS() Function

**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/postgresql-date-functions/postgresql-age)
- [AT TIME ZONE Operator](https://neon.com/postgresql/postgresql-date-functions/postgresql-at-time-zone)
- [CLOCK_TIMESTAMP](https://neon.com/postgresql/postgresql-date-functions/postgresql-clock_timestamp)
- [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_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)
