Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
wided
Posting Yak Master
218 Posts |
Posted - 2015-01-16 : 04:12:32
|
hellooI have 2 dates (period)I need to extract the last day of each week in this periodthanks |
|
nagino
Yak Posting Veteran
75 Posts |
Posted - 2015-01-16 : 04:49:25
|
[code]DECLARE @From DateTime = '2015-01-10';DECLARE @To DateTime = '2015-01-25';SET DATEFIRST 6; --if 'last day of week' means saturday, set 6.WITH dates ([day], [week]) AS (SELECT @From, DATEPART(ww, @From) [week]UNION ALLSELECT DATEADD(d, 1, [day]), DATEPART(ww, [day]) [week]FROM datesWHERE DATEADD(d, 1, [day]) <= @To)SELECT MAX([day])FROM datesGROUP BY [week];[/code]-------------------------------------From JapanSorry, my English ability is limited. |
|
|
wided
Posting Yak Master
218 Posts |
Posted - 2015-01-16 : 05:46:20
|
thanks naginoit's ok |
|
|
|
|
|