Typecast character or string to date in Postgresql

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

  • Typecast Character or string to date in Postgresql

We will be using orders_new table.

Typecast character or string to date in Postgresql 1

 

Typecast character or string to date in Postgresql:

Method 1: Using :: to typecast

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

select *,received_text::date as received_date from orders_new

So the resultant dataframe with received_text column typecasted will be

Typecast character or string to date in Postgresql 2

 

Method 2: Using CAST()  function to typecast

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


select *,cast(received_text as date) as received_date from orders_new

So the resultant dataframe with received_text column typecasted will be

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