Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the Time from now() function in postgres

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.

like image 955
juanpscotto Avatar asked Dec 06 '25 01:12

juanpscotto


2 Answers

Instead of extracting it from now you could just use the builtin field:

SELECT CURRENT_TIME
like image 57
Mureinik Avatar answered Dec 08 '25 13:12

Mureinik


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');
like image 32
A. Scherbaum Avatar answered Dec 08 '25 13:12

A. Scherbaum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!