Deni Suryadi
Deni Suryadi

Reputation: 31

Convert this Sql Query to Postgresql please

How can i use this in postgresql?

SELECT *
FROM table
WHERE MONTH(columnName) = MONTH(CURRENT_DATE())
AND YEAR(columnName) = YEAR(CURRENT_DATE())

Upvotes: 0

Views: 38

Answers (3)

Laurenz Albe
Laurenz Albe

Reputation: 247865

The simplest solution might be

SELECT * FROM atable
WHERE date_trunc('month', columnname) = date_trunc('month', current_timestamp);

That function rounds the timestamp down to the specified precision, in this case to the beginning of the month.

Upvotes: 0

freqnseverity
freqnseverity

Reputation: 136

Use CURRENT_TIMESTAMP and extract the month.

select EXTRACT(month from CURRENT_TIMESTAMP);

Upvotes: 0

pifor
pifor

Reputation: 7892

You can use current_date and date_part;

postgres=# select date_part('month', current_date) as month,  
                  date_part('year', current_date) as year;
 month | year 
-------+------
     7 | 2020
(1 row)

Upvotes: 1

Related Questions