Saturday, February 25, 2012

Dates of a week

Hi! I have the week number and the year. I want get all the dates that fall
in that week.
Is anyone who has idea to get this?
Barentry this
CREATE FUNCTION [dbo].[fnStartDayOfWeek](
@.date datetime )
RETURNS datetime
BEGIN
SET @.date = CONVERT(varchar(10), @.date, 111)
RETURN DATEADD(DD, 1 - DATEPART(DW, @.date), @.date)
END
GO
CREATE FUNCTION [dbo].[fnLastDayOfWeek](
@.date datetime )
RETURNS datetime
BEGIN
SET @.date = CONVERT(varchar(10), @.date, 111)
RETURN DATEADD(DD, 1 - DATEPART(DW, @.date)+6, @.date)
END
GO
DECLARE @.StartOfYear varchar(10)
DECLARE @.year varchar(4)
DECLARE @.WeekNo int
SET @.WeekNo = 2
SET @.Year = '2005'
SET @.StartOfYear = @.Year+'0101'
SELECT dbo. fnLastDayOfWeek(DATEADD(dd,7*@.WeekNo,@.St
artOfYear) )
SELECT dbo. fnStartDayOfWeek(DATEADD(dd,7*@.WeekNo,@.S
tartOfYear) )
Aneessh R
"Baren" <Baren@.discussions.microsoft.com> wrote in message
news:2216A3EB-5EA3-4BA3-9119-0758F4A055F2@.microsoft.com...
> Hi! I have the week number and the year. I want get all the dates that
> fall
> in that week.
> Is anyone who has idea to get this?
> Baren|||There are many good reasons to have a 'calendar' table in your database.
This is one of them.
See:
http://www.aspfaq.com/show.asp?id=2519
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Baren" <Baren@.discussions.microsoft.com> wrote in message
news:2216A3EB-5EA3-4BA3-9119-0758F4A055F2@.microsoft.com...
> Hi! I have the week number and the year. I want get all the dates that
> fall
> in that week.
> Is anyone who has idea to get this?
> Baren

No comments:

Post a Comment