【请问】如何把会计期间换算为自然期间,

huaxiaoxi 2007-10-24 02:30:45
比如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

我应该如何判断,谢谢了啊
...全文
74 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huaxiaoxi 2007-10-25
  • 打赏
  • 举报
回复
呵呵,大家人真好,接帖了啊
dobear_0922 2007-10-24
  • 打赏
  • 举报
回复
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)
*/



dobear_0922 2007-10-24
  • 打赏
  • 举报
回复
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)
*/

dawugui 2007-10-24
  • 打赏
  • 举报
回复
定义一个表

月份 开始日期 结束日期
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)+结束日期

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧