Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way convert text to time in postgresql?

Is there any way convert text to time type? Code in postgresql as below:

to_char(localtimestamp(0),'HH24:mi:SS')

this way I will get the value like 15:15:20,but this type is varchar(or text).
How can I do to get the value in time type?

Thanks!

like image 829
Edward Avatar asked Jan 15 '13 07:01

Edward


People also ask

What is the datatype for time in PostgreSQL?

What is PostgreSQL Time Data Type? In PostgreSQL, the next data type is TIME, which stores the Time of days values. The PostgreSQL Time Data type involves 8 bytes of storage and up to 6 digits of precision, and the range starts from 00:00:00 to 24:00:00 for Time data type.

How do I get system time in PostgreSQL?

The PostgreSQL function CURRENT_TIME returns the current time and time zone offset of the machine on which PostgreSQL is running. It is given as a value in the 'hh:mm:ss. nnnnnn+/-tz' format.

What is extract epoch in PostgreSQL?

YES, you can convert EPOCH to Timestamp by merely switching to the present Timestamp in PostgreSQL DBMS. EPOCH time is nothing but the number of seconds from 00:00:00 UTC on 1 January 1970. Till date, without adding the extra leap year days, this is considered. Furthermore, every day treated as 86400 seconds.

How do I cast an expression in PostgreSQL?

PostgreSQL supports a CAST operator that is used to convert a value of one type to another. Syntax: CAST ( expression AS target_type ); Let's analyze the above syntax: First, specify an expression that can be a constant, a table column, an expression that evaluates to a value.


1 Answers

SELECT  TO_TIMESTAMP('15:15:20', 'HH24:MI:SS')::TIME

Note that your very query (which returns local time) can be rewritten as

SELECT  LOCALTIME

which would return TIME

like image 138
Quassnoi Avatar answered Oct 21 '22 09:10

Quassnoi