Nitheesh K P
Nitheesh K P

Reputation: 1110

how to get the current year from postgres sql query

how to get the current year from postgresql query, I tried like normal mysql query .But this is not working in postgresql?

SELECT YEAR(CURDATE());

Upvotes: 0

Views: 7875

Answers (3)

user330315
user330315

Reputation:

In standard ANSI SQL (which is also supported by Postgres) this would be:

extract(year from current_date)

Upvotes: 1

grepit
grepit

Reputation: 22382

you could also do this

select date_part('year', CURRENT_DATE);

Upvotes: 2

Rémy  Baron
Rémy Baron

Reputation: 1399

try :

  select to_char(now(),'YYYY')

Upvotes: 4

Related Questions