Suryakala
Suryakala

Reputation: 49

How to extract hour from timestamp?

I have taken only the time value from systimestamp. But with the same i need to extract hour from time value.

SELECT EXTRACT (HOUR FROM TO_CHAR(systimestamp,'hh24:mi:ss'')) FROM DUAL ;

but I'm getting "invalid extract field for extract source"

Upvotes: 0

Views: 2971

Answers (2)

Popeye
Popeye

Reputation: 35900

You can also use to_char as follows:

SELECT to_char(systimestamp,'hh24') FROM DUAL

Upvotes: 2

T-Moar
T-Moar

Reputation: 43

It looks like you're converting your timestamp to a character, which means it doesn't have an hour value for you to extract.

Try taking systimestamp out of the function.

SELECT EXTRACT(HOUR FROM systimestamp) FROM DUAL;

Upvotes: 3

Related Questions