Get QUARTER from Timestamp in Postgresql

In order to Get quarter from Timestamp in postgresql we use Extract Keyword. Within the Extract keyword we have to mention QUARTER as we are getting quarter from timestamp

Let’s see how to

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

With an example for both

 

Extract QUARTER from Timestamp in Postgresql:

Within the Extract keyword we have to mention QUARTER as we are getting quarter from timestamp

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

So the resultant quarter will be

Get quarter from timestamp 2

 

 

EXTRACT QUARTER from Timestamp in column of Postgresql table:

We use table student_detail

Get quarter from timestamp 1

 

Create the column which extracts QUARTER from timestamp column in Postgresql

We have created a column and stored QUARTER from Birthdaytime column

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

So the resultant table will be

Get quarter from timestamp 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.