I have a store function.
I want to get only the time from the now() function in Postgres. How Can i do it?
I know that for the date you can use DATE(now()), but for the time I tried TIME(now()), but it does not work.
Instead of extracting it from now you could just use the builtin field:
SELECT CURRENT_TIME
CURRENT_TIME returns the current time with timezone, LOCALTIME returns the time without timezone information. You can specify the precision:
SELECT CURRENT_TIME(0);
SELECT LOCALTIME(0);
Another way is to use to_char() and format the time the way you want it:
SELECT to_char(NOW(), 'HH24:MI:SS');
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