如何知道某时间段有多少天?

想飞的狼 2007-12-25 09:49:01
有一个变量@t='20040428'
想知道从@t到04年底有多少天?
...全文
113 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gimse7en 2007-12-25
  • 打赏
  • 举报
回复
学习~
wzy_love_sly 2007-12-25
  • 打赏
  • 举报
回复
declare @star datetime,@end datetime
set @star=getdate()
set @star=convert(varchar(10),@star,12)
select '元旦'=datediff(dd,@star,cast(cast(datepart(yy,@star)+1 as varchar(10))+'-01-01' as datetime)-1)

元旦
6
dawugui 2007-12-25
  • 打赏
  • 举报
回复
[code=SQL]declare @t as datetime
set @t = '20040428'

select 天数 = datediff(day , @t , '2004-12-31')
select 加修正值的天数 = datediff(day , @t , '2004-12-31') + 1

/*
天数
-----------
247

(1 行受影响)

加修正值的天数
-----------
248

(1 行受影响)
*/

[/code]
dawugui 2007-12-25
  • 打赏
  • 举报
回复
declare @t as datetime
set @t = '20040428'

select 天数 = datediff(day , @t , '2004-12-31')
select 加修正值的天数 = datediff(day , @t , '2004-12-31') + 1

/*
天数
-----------
247

(1 行受影响)

加修正值的天数
-----------
248

(1 行受影响)
*/

wzy_love_sly 2007-12-25
  • 打赏
  • 举报
回复
declare @star datetime,@end datetime
set @star='20071225'
set @star=convert(varchar(10),@star,12)
select datediff(dd,@star,cast(cast(datepart(yy,@star)+1 as varchar(10))+'-01-01' as datetime)-1)
leo_lesley 2007-12-25
  • 打赏
  • 举报
回复
declare @t varchar(20)

set @t='20040428'
select datediff(day,cast(@t as datetime),'2005-01-01')
wzy_love_sly 2007-12-25
  • 打赏
  • 举报
回复
declare @star datetime,@end datetime
set @star='2007-12-10 09:51:02.170'
set @end='2007-12-25 09:51:02.170'
select datediff(dd,@star,@end)

15

34,590

社区成员

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

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