日期转会计期

SUBSTRING(CONVERT(VARCHAR,getdate(), 20), 1, 7)   2015-06

SUBSTRING(CONVERT(VARCHAR,DATEADD(mm,-1,GETDATE()), 20), 1, 7) 上个会计期

Convert(varchar(6),getdate(),112) 日期格式 201501

本月第一天

dateadd(dd,-day(getdate())+1,getdate()) 

上月最后一天

dateadd(dd,-day(getdate()),getdate())

当月最后一天

dateadd(dd,-day(getdate()),dateadd(m,1,getdate()))

根据会计期间获得前12月的开始时间
SELECT DATEADD(MONTH,-11, CAST('2015-06'+'-01' AS DATE))

获取两个日期间的天数
DATEDIFF (day,v1.fdate,isnull(v5.fdate,getdate()))

sql report server里的相关日期转换

报表工具:上一个会计期间
=CStr(year(DateAdd(DateInterval.Month, -1, today())))&"-"&IIf(month(DateAdd(DateInterval.Month, -1, today()))>=10,CStr(month(DateAdd(DateInterval.Month, -1, today()))),"0"&CStr(month(DateAdd(DateInterval.Month, -1, today()))))

年初
=CStr(year(DateAdd(DateInterval.Month, -1, today())))&"-01"

最近6个月
=CStr(year(DateAdd(DateInterval.Month, -6, today())))&"-"&IIf(month(DateAdd(DateInterval.Month, -6, today()))>10,CStr(month(DateAdd(DateInterval.Month, -6, today()))),"0"&CStr(month(DateAdd(DateInterval.Month, -6, today()))))