Typecast character or string to timestamp in Postgresql

In order to typecast character or string to timestamp in postgresql we will be using cast() function. With the help of cast() function we will be able to typecast character or string  to timestamp in postgresql. Let’s see how to

  • Typecast Character or string to timestamp in Postgresql

We will be using orders_new table.

Typecast character or string to timestamp in Postgresql 1

 

Typecast character or string to timestamp in Postgresql:

Method 1: Using :: to typecast

Column name followed by :: and followed by timestamp is used to typecast received_text column.


select *,received_text::timestamp as received_timestamp from orders_new

So the resultant dataframe with received_text column typecasted will be

Typecast character or string to timestamp in Postgresql 2

 

Method 2: Using CAST()  function to typecast

CAST() function with Argument column_name as  timestamp is used to typecast received_text column.


select *,cast(received_text as timestamp) as received_timestamp from orders_new

So the resultant dataframe with received_text column typecasted will be

Typecast character or string to 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.

    View all posts