I have a date and I want to get just the year from it as an integer.
-
2a google search would've helped you.Vamsi Prabhala– Vamsi Prabhala2017-04-13 16:57:48 +00:00Commented Apr 13, 2017 at 16:57
-
extract(year from datecol)::intOto Shavadze– Oto Shavadze2017-04-13 17:05:17 +00:00Commented Apr 13, 2017 at 17:05
-
@vkp i apologise im really new on pgsql and sql in general and i was confused with the google results as they ended up as dates or characters from extracting. all i needed was a simple integer format on top of that which i thought after seeing the suggestionsLaprimoSiesta– LaprimoSiesta2017-04-13 17:19:16 +00:00Commented Apr 13, 2017 at 17:19
-
@OtoShavadze thanks a lotLaprimoSiesta– LaprimoSiesta2017-04-13 17:19:29 +00:00Commented Apr 13, 2017 at 17:19
Add a comment
|
2 Answers
It's pretty simple, really...
SELECT year([datecolumn])
FROM [yourTable]
Since that will be nothing more than a 4-digit number, you can use it as an integer wherever you go.
3 Comments
Evan Carroll
There is no year function in pg.
durbnpoisn
Ah. I saw SQL tag and went with that.
Evan Carroll
year() has nothing to do with SQL. It's a SQL Server flub, one of the very many ways it breaks the spec.