名称和两个日期之间的天数 [英] Name and number of days between two dates

查看:71
本文介绍了名称和两个日期之间的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要获取两个日期之间的名称和天数. SQL中是否有函数或方法可以做到这一点.

例如:2012年6月15日至2012年6月30日之间有几个星期日,星期一,.....星期六.

Thnx

Hi
I need to get the name and number of days between two dates. is there a function or a way in SQL to do that.

example: how many sundays, mondays,....., saturdays are in between 15 june 2012 and 30th june 2012.

Thnx

推荐答案

没有内置函数可以执行此操作,您必须编写自己的函数.我建议您首先查看以下内容: http://forums.asp.net/t/1439809.aspx/1 [ ^ ]
这是: http://stackoverflow.com /questions/8642870/calculate-all-sundays-mondays-saturdays-between-two-days-in-sql-server [
There is no built in function to do that, you will have to write your own. I suggest you start by looking at this: http://forums.asp.net/t/1439809.aspx/1[^]
And this: http://stackoverflow.com/questions/8642870/calculate-all-sundays-mondays-saturdays-between-two-days-in-sql-server[^]


DATEDIFF 功能 [
The DATEDIFF function[^] should be sufficient for your requirement.

E.g.
select DATEDIFF(DAY, @date1,@date2)



检查此
Hi ,
Check this
declare @t1 nvarchar(10)
set @t1 ='1/1/2010'
declare @t2 nvarchar(10)
set @t2 ='1/3/2010'

select datediff(DAY,convert(datetime, convert(char(10), @t1,110)),convert(datetime, convert(char(10),@t2, 110)))


最好的问候
米特瓦里(M.Mitwalli)


Best Regards
M.Mitwalli


这篇关于名称和两个日期之间的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆