I am trying to extract the month from the the Order_date column by using postgres SQL , and the format is required to come in the name of the month format ;for example, December.
When I applied the extract function , It gave me an error message saying that the date setting has to be changed.
Please advise how to extract the month from the mentioned column ?
The data has been enclosed
SELECT EXTRACT(MONTH FROM order_date::date)
FROm think_sales;
The error message :
[22008] ERROR: date/time field value out of range: "25/06/2021" Hint: Perhaps you need a different "datestyle" setting.
Data :
3
Answers
This work for me:
SELECT EXTRACT(MONTH FROM TIMESTAMP ’25/06/2021′);
https://www.postgresqltutorial.com/postgresql-date-functions/postgresql-extract/
You may need to define your date format using the to_date function:
Output:
June
In your case, you would use:
set date format to dmy (day – month – year )
This answer