[英]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 ? 我想只获取年份,并且只获取日期中的数字月份,我尝试通过char char month来进行月份查询,如何获取数字month和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;
Or: 要么:
select to_char(dateper, 'YYYY-MM')
from calcul
group by to_char(dateper, 'YYYY-MM') ;
Month: 月:
SELECT date_part('month', now())::integer;
Year: 年:
SELECT date_part('year', now())::integer;
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 请参考此页
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.