Fix Error “time field value out of range” when using make_time() in PostgreSQL

If you’re getting an error that reads ‘time field value out of range‘ in PostgreSQL while using the make_time() function, it’s probably because one or more of the time parts you’re providing is out of the accepted range for that time part.

To fix this issue, be sure that each time part you provide is within the valid range for that time part.

Example of Error

Here’s an example of code that produces the error:

SELECT make_time(25, 45, 15.08);

Result:

ERROR:  time field value out of range: 25:45:15.08

Here I specified 25 for the hour part, but the hour part cannot be higher than 24.

Also, if the hour is 24, the minutes and seconds can’t be higher than zero. So the following also fails:

SELECT make_time(24, 0, 0.01);

Result:

ERROR:  time field value out of range: 24:00:0.01

Solution

The solution is to use valid time parts. With make_time(), the first argument is for the hour, the second argument is for the minutes, and the third is for the seconds.

So let’s change it to a value that fits within the accepted range:

SELECT make_time(23, 45, 15.08);

Result:

  make_time  
-------------
23:45:15.08

This time it worked without error.