I'm trying to extract the time of day from a 'timestamp' column in PostgreSQL. Here is how I did it but... it's awful. An idea of how to do it better ?
SELECT (
date_part('hour', date_demande)::text || ' hours ' ||
date_part('minute', date_demande)::text || ' minutes ' ||
date_part('second', date_demande)::text || ' seconds'
)::interval AS time_of_day
FROM table;
If you need the exact time from a timestamp, just cast to time:
SELECT
CAST(colname AS time)
FROM
tablename;
If you need formatting, to_char() is your best option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With