PostgreSQL justify_days() Function

The PostgreSQL justify_days() function converts the representation of time intervals, converting the number of days over 30 days to the number of months.

justify_days() Syntax

Here is the syntax of the PostgreSQL justify_days() function:

justify_days(value INTERVAL) -> INTERVAL

Parameters

value

Required. The interval value to convert.

Return value

The PostgreSQL justify_days() function converts the representation of time intervals, converting the number of days over 30 days to the number of months.

If the given interval value is less than 30 days, no conversion will be done.

justify_days() Examples

The following example shows the basic usage of the justify_days() function.

SELECT
    justify_days(INTERVAL '20 days') AS "20 days",
    justify_days(INTERVAL '70 days') AS "70 days",
    justify_days(INTERVAL '1 year 40 days') AS "1 year 40 days";
 20 days |    70 days     |    1 year 40 days
---------+----------------+----------------------
 20 days | 2 mons 10 days | 1 year 1 mon 10 days