khadi8 khadi8 - 1 year ago 81
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 Source

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') ;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download