How can I use function least/greatest in PostgreSQL on timestamp column?
I have a column - plc_time (timestamp without time zone) and I need to select rows where the plc_time is greatest from two values (the value is timestamp without time zone).
Should I use the conversion? How can I do it?
To calculate the difference between the timestamps in PostgreSQL, simply subtract the start timestamp from the end timestamp. Here, it would be arrival - departure . The difference will be of the type interval , which means you'll see it in days, hours, minutes, and seconds.
Don't use timestamp (without time zone) to store UTC times Storing UTC values in a timestamp without time zone column is, unfortunately, a practice commonly inherited from other databases that lack usable timezone support. Use timestamp with time zone instead.
The PostgreSQL function LOCALTIMESTAMP returns the current date and time (of the machine running that instance of PostgreSQL) as a timestamp value. It uses the 'YYYY-MM-DD hh:mm:ss. nnnnnnn' format, where: YYYY is a 4-digit year.
The PostgreSQL CURRENT_TIME function returns the current time and the currentthe time zone.
select *
from some_table
where plc_time = greatest(timestamp '2013-07-15 14:55:00', timestamp '2013-03-01 17:43:00');
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