khadi8 khadi8 - 6 months ago 37
SQL Question

get only month and year from date

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


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;


select to_char(dateper, 'YYYY-MM') 
from calcul
group by to_char(dateper, 'YYYY-MM') ;