Get Milliseconds from Timestamp in Postgresql

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

Let’s see how to

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

With an example for both

Extract milliseconds from Timestamp in Postgresql:

Within the Extract keyword we have to mention MILLISECONDS as we are getting milliseconds from timestamp

SELECT EXTRACT (MILLISECONDS FROM TIMESTAMP '2011-11-22 13:30:15.203')

So the resultant MILLISECONDS will be

Get Millisecond from timestamp in postgresql in 2

 

EXTRACT milliseconds from Timestamp in column of Postgresql table:

We use table student_detail

Get Millisecond from timestamp in postgresql in 1

 

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

We have created a column and stored milliseconds from Birthdaytime column

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

So the resultant table will be

Get Millisecond from timestamp in postgresql in 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.