Zakir Hossain
Zakir Hossain

Reputation: 444

How to solve an error while converting timestamp to time?

I have a database table name "c_pay_daily_attend as da" in postgresql like:

Name da.outime6
Zakir 2018-09-06 15:00:00

I want just time like this:

Name da.outime6
Zakir 15:00:00

I am using

TO_TIMESTAMP(da.outime6, 'HH24:MI:SS')::TIME 

but it is getting the following error

ERROR:  function to_timestamp(timestamp without time zone, unknown) does not exist
LINE 1: select TO_TIMESTAMP(da.intime6, 'HH24:MI:SS')::TIME ee,bp.c_...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts. 

How do I solve this?

Upvotes: 1

Views: 657

Answers (3)

Fahmi
Fahmi

Reputation: 37473

use cast() function

SELECT Cast(da.outime6 :: timestamp AS TIME) 
FROM   c_pay_daily_attend AS da 

Upvotes: 1

user330315
user330315

Reputation:

outime6 seems to be already a timestamp, so there is no need to convert it first.

Just cast it to a time value:

da.outime6::time

Upvotes: 1

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32003

use time conversion below way

select CURRENT_TIMESTAMP::time

demo in fiddle

Upvotes: 2

Related Questions