MAKE_INTERVAL
Creates an interval from years, months, weeks, days, hours, minutes and seconds.
PostgreSQL 17.5
MAKE_INTERVAL([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]])Parameters
- yearsintegeroptional
- Number of years, 0 by default
- monthsintegeroptional
- Number of months, 0 by default
- weeksintegeroptional
- Number of weeks, 0 by default
- daysintegeroptional
- Number of days, 0 by default
- hoursintegeroptional
- Number of hours, 0 by default
- minsintegeroptional
- Number of minutes, 0 by default
- secsdouble precisionoptional
- Number of seconds, can be fractional, 0 by default
Return value
An interval; weeks are converted to days, seconds to hours and minutes
Examples
Interval from a named argument
PostgreSQL 17.5
SELECT MAKE_INTERVAL(days => 10);Interval from seconds
PostgreSQL 17.5
SELECT MAKE_INTERVAL(0, 0, 0, 0, 0, 0, 3661);Timestamp in two weeks
PostgreSQL 17.5
SELECT CURRENT_DATE + MAKE_INTERVAL(weeks => 2) AS in_two_weeks;Details
It is convenient to pass the arguments by name: MAKE_INTERVAL(days => 10). A date plus an interval gives a timestamp, so CURRENT_DATE + MAKE_INTERVAL(weeks => 2) returns the moment 00:00 two weeks from now.