Is there a function that takes a year, month and day to create a date in PostgreSQL?

user142019 picture user142019 · Mar 10, 2013 · Viewed 24.9k times · Source

In the docs I could only find a way to create a date from a string, e.g. DATE '2000-01-02'. This is utterly confusing and annoying. What I want instead is a function that takes three parameters, so I could do make_date(2000, 1, 2) and use integers instead of strings, and returns a date (not a string). Does PostgreSQL have such a built-in function?

The reason I'm asking this is because I dislike the use of strings for things that are not strings. Dates are not strings; they're dates.

The client library I use is HDBC-PostgreSQL for Haskell. I'm using PostgreSQL 9.2.2.

Answer

Gregory Arenius picture Gregory Arenius · Feb 3, 2016

In PostgreSQL 9.4 and greater there is actually a make_date(year int, month int, day int) function that will create a date.

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