解析日期问题,在线急等
我想把一个日期如:2007-07-31解析出这一天是7月的第几个周,是这个季度的第几个周
怎么做啊,
[解决办法]
select top 366 id=identity(int,0,1)into # from syscolumns
select id,dateadd(day,id, '2007-01-01 ') r,month(dateadd(day,id, '2007-01-01 ')) m,
datepart(week,dateadd(day,id, '2007-01-01 ')) w,
datepart(q,dateadd(day,id, '2007-01-01 ')) q into #t
from # where year(dateadd(day,id, '2007-01-01 '))=2007
select count(distinct w) 季周
from #t
where q=datepart(q, '2007-07-31 ') and datediff(day,r, '2007-07-31 ')> =0
select count(distinct w) 月周
from #t
where m=month( '2007-07-31 ') and datediff(day,r, '2007-07-31 ')> =0
drop table #,#t