日期:2014-05-18  浏览次数:20572 次

【请问】如何把会计期间换算为自然期间,
比如2007-01-25 到 2007-02-25 为二月
输入的是一个自然期间比如 2007-01-27 理论上应该是1月,但是实际上在软件中确是2月
而软件中存储的是形式是这样的

2007-01-25
2007-02-25
2007-03-25
2007-04-25
2007-05-25

我应该如何判断,谢谢了啊

------解决方案--------------------
SQL code
定义一个表

月份  开始日期  结束日期
1     12-26     01-25
2     01-26     02-25
3     02-26     03-25
4     03-26     04-25
5     04-26     05-25
6     05-26     06-25

....................

declare @riqi as datetime
set @riqi = '2007-01-27'

if (datepart(month,@riqi) = 11 and datepart(day,@riqi) > 25) or
   (datepart(month,@riqi) = 12 and datepart(day,@riqi) <= 25)
   print '12月份'
else
   if (datepart(month,@riqi) = 12 and datepart(day,@riqi) > 25) or
      (datepart(month,@riqi) = 1 and datepart(day,@riqi) <= 25) 
      print '1月份'
   else
      select 月份 from tb where @riqi >= datename(year,@riqi)+开始日期 and @riqi <= datename(year,@riqi)+结束日期

------解决方案--------------------
SQL code
declare @date datetime
set @date='2007-1-27'
select Mon=case when datepart(day,@date)>=25 then datepart(month,@date)+1 else datepart(month,@date) end 
/* result
        Mon
-----------
          2

(1 row(s) affected)
*/

------解决方案--------------------
SQL code
declare @date datetime
set @date='2007-12-27'
select Mon=case when datepart(day,@date)>=25 then datepart(month,@date)%12+1 else datepart(month,@date) end 

/* result
        Mon
-----------
          1

(1 row(s) affected)
*/