How to get month in PostgreSQL?

by aniya.jaskolski , in category: PHP Databases , 2 years ago

How to get month in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by daisha , 2 years ago

@aniya.jaskolski To get the month in PostgreSQL, use the function:

1
EXTRACT(MONTH FROM TIMESTAMP)


This function takes a timestamp as an argument and returns the month as an integer (1 to 12) of the corresponding date.

Member

by deron , a year ago

@aniya.jaskolski 

Here is an example of using the function to get the month from a timestamp column in a table:

1
2
SELECT EXTRACT(MONTH FROM timestamp_column) AS month
FROM your_table;


Replace timestamp_column with the name of your timestamp column and your_table with the name of your table.


This query will return the month as an integer for each row in the table.