[SOLVED] How to extract date from string

Issue

I’m working on PostgreSQL with SQL.

I have a column date that is a string and I want to extract the month:

enter image description here

I tried:

SELECT EXTRACT(MONTH FROM cast(date as date)) FROM table_name ;

I got:

ERROR: ERREUR: syntaxe en entrée invalide pour le type date : « janvier 2020 »

Can anyone help me please?

Solution

try

select  
    split_part(date, ' ', 2) as month
from table_name

.

Answered By – Shadiqur

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *