|
Home > Archive > ASE Database forum > October 2005 > Date Calculation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| tsmein 2005-10-27, 8:21 am |
| Hello,
is there a function or procedure that is able to calculate
the date
base on a given year , a given week and a given dayofweek?
Regards
| |
| tartampion 2005-10-27, 8:21 am |
| Would the following code help at all?
-----------------------------------------
Suppose that we want to have the date of today, knowing the
end of week of the year (43), day of the week (Thu 5), then
we can prcoceed as follows:
set nocount on
declare @d1 datetime, @d2 datetime, @wk int, @wd int, @i int
select @wk=43 -- end of present week
select @wd=5 -- number of Thursday in the week
select @d1=convert (datetime, "20050101") -- begining of the
year
select @d2=convert (datetime,"19000101") -- this can be
17530101
select @i=(datediff (dd,@d2,@d1)) + ((-2 + @wk) *7) +@wd
select dateadd(dd,@i,@d2)
If this is acceptable, then it can be transformed and
written as a store dprocedure taking 3 input parameter:
year, week, day
> Hello,
>
> is there a function or procedure that is able to calculate
> the date
> base on a given year , a given week and a given dayofweek?
>
> Regards
| |
| tsmein 2005-10-27, 8:21 am |
| Thanks a lot for that solution, it works great
Regards
[color=darkred]
> Would the following code help at all?
> -----------------------------------------
> Suppose that we want to have the date of today, knowing
> the end of week of the year (43), day of the week (Thu 5),
> then we can prcoceed as follows:
>
> set nocount on
> declare @d1 datetime, @d2 datetime, @wk int, @wd int, @i
> int select @wk=43 -- end of present week
> select @wd=5 -- number of Thursday in the week
> select @d1=convert (datetime, "20050101") -- begining of
> the year
> select @d2=convert (datetime,"19000101") -- this can be
> 17530101
> select @i=(datediff (dd,@d2,@d1)) + ((-2 + @wk) *7) +@wd
> select dateadd(dd,@i,@d2)
>
> If this is acceptable, then it can be transformed and
> written as a store dprocedure taking 3 input parameter:
> year, week, day
> dayofweek? >
|
|
|
|
|