khadi8 khadi8 - 1 month ago 7
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

Answer

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') ;
Comments