Reputation: 65
I want get only year, and only numeric month from date, I try this for month by i get char month, how can i get numeric month, and year ?
select to_char(dateper,'MON')
from calcul
group by dateper
Upvotes: 0
Views: 23162
Reputation: 1269593
You can get a numeric representation in a string by using:
select extract(year from dateper) as yyyy, extract(month from dateper) as mm
from calcul
group by yyyy, mm;
Or:
select to_char(dateper, 'YYYY-MM')
from calcul
group by to_char(dateper, 'YYYY-MM') ;
Upvotes: 1
Reputation: 206
Month:
SELECT date_part('month', now())::integer;
Year:
SELECT date_part('year', now())::integer;
Upvotes: 1
Reputation: 3429
You can try this one:
datename(m,column)+' '+cast(datepart(yyyy,column) as varchar) as MonthYear
or
select to_char(DATEFIELD,'MON') from YOUR_TABLE
please Refer This Page
Upvotes: 0