Get Hour from Timestamp in Postgresql

In order to get hour from Timestamp in postgresql we use Extract Keyword. Within the Extract keyword we have to mention HOUR as we are getting HOUR from timestamp

Let’s see how to

  • Extract hour from Timestamp in Postgresql
  • Create the column which extracts hour from timestamp column

With an example for both

 

Extract hour from Timestamp in Postgresql:

Within the Extract keyword we have to mention HOUR as we are getting hour from timestamp

SELECT EXTRACT (HOUR FROM TIMESTAMP '2011-11-22 13:30:15')

So the resultant HOUR will be

Get Hour from timestamp in Postgresql 2

 

EXTRACT hour from Timestamp in column of Postgresql table:

We use table student_detail

Get Hour from timestamp in Postgresql 1

 

 

Create the column which extracts HOUR from timestamp column in Postgresql:

We have created a column and stored hour from Birthdaytime column

SELECT *,EXTRACT (HOUR FROM Birthdaytime) AS HOUR FROM Student_detail

So the resultant table will be

Get Hour from timestamp in Postgresql 3

 

                                                                                                 

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.