1

I'm using Postgres 9.1 and try to get records from a table knowing the given month and should know if the date type date field contains the month.

This is my query:

SELECT consejo.numero,consejo.fecha FROM consejo WHERE MONTH(consejo.fecha) = 2

but I get the following error:

ERROR: There is no month function (date)
LINE 1: ... T consejo.numero, consejo.fecha council FROM WHERE MONTH (cons ...

HINT: No function matches the name and types of arguments. You may need to add explicit type conversion.

might be wrong?

user1813375
  • 101
  • 3
  • 12

2 Answers2

3

In Postgresql there is no MONTH function available. You can use EXTRACT instead:

WHERE EXTRACT(MONTH FROM consejo.fecha) = 2
Giorgos Betsos
  • 71,379
  • 9
  • 63
  • 98
0

Another option is to use PostgreSQL's date_part() function:

 WHERE date_part('month', consejo.fecha) = 2

Look at the reference guide:

http://www.postgresql.org/docs/9.5/static/functions-datetime.html

Rodrigo Hjort
  • 301
  • 3
  • 5