Table / Time element and the N/A problem

I am trying to use a time element/ picker in a table row. It is only time, not date/time. If I am creating a new row it works correctly, but when I populate the row from sql, it shows N/A. When I try and save in edit, it appears that it’s trying to pre-pend the date, which is is only a time field with timezone from postgres. I have tried casting with AT TIME ZONE ‘UTC’ AS I have tried ::time I have tried writing a java script to populate instead of from the SQL select directly all to no avail. If I just make it a string field, it shows everything correctly, but I loose the picker. Any one have any experience with this?

Hi @TNelson

The Time picker currently expects a full date/time value internally, even though it displays only the time. PostgreSQL time and time with time zone fields are usually returned as time-only strings, such as 14:30:00+00. The picker cannot parse that value without a date, so it displays N/A. When edited, it returns a full date/time value for the same reason.

As a workaround, add a placeholder date in your SELECT query:

SELECT
  CURRENT_DATE + my_time::time AS my_time
FROM my_table;

If the value should be interpreted as UTC:

SELECT
  (CURRENT_DATE + my_time::time) AT TIME ZONE 'UTC' AS my_time
FROM my_table;

This provides the complete value required by the picker while it continues to display only the time.

When saving, cast the picker’s returned value back to the PostgreSQL column type:

UPDATE my_table
SET my_time = $1::timestamptz::timetz
WHERE id = $2;

Here, $1 is the value returned by the Time picker. This removes the technical date before storing the value in the timetz column.

Thank you SO MUCH! That worked perfectly!

1 Like