日期:2014-05-17  浏览次数:20593 次

求一个日期处理函数
公司账期是26号到下月25号。比如我2012年12月28日有一票出货纪录,是算到2013年1月的业绩里面的。我希望能有一个函数
f(出货日期)返回我要的月份结果
f(2012-12-28)返回'2013-01'
谢谢大家!

------解决方案--------------------

alter function fShowCountDate(@shipdate varchar(10))
returns  varchar(7)
as 
begin 
return case when datepart(d,@shipdate)>=26 then convert(varchar(7),dateadd(m,1,@shipdate),120)
    when datepart(d,@shipdate)<=25 then substring(@shipdate,1,7) else '' end
end