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 |
|
kiranmurali
Yak Posting Veteran
55 Posts |
Posted - 2010-07-19 : 01:38:43
|
| how to get the week number,week start in integer,week end in integer for a given date?i have to populate these datas in master table based on the given date.pls give me some suggestions to write a function or stored procedure.Thanks in Advance.Kiran |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-07-19 : 02:14:31
|
| do u need this?select datepart(wk,getdate()) as Week_of_the_year,datepart(dy,getdate())as day_of_the_year,datepart(dy,getdate())+(7-datepart(dw,getdate()))-6 as start_day_of_the_week,datepart(dy,getdate())+(7-datepart(dw,getdate())) as end_day_of_the_weekSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
kiranmurali
Yak Posting Veteran
55 Posts |
Posted - 2010-07-19 : 03:21:46
|
THIS IS WORKING FINE I NEED DAY(DATE) OF THE START WEEK AND THE WEEEND DAY(DATE) FOR EXAMPLETODAY IS 19/07/2010 WEEK START SHOULD DISPLAY 19END OF THE WEEK 25 THAT IS COMING SUNDAYTHANKS IN ADVANCEKIRANquote: Originally posted by senthil_nagore do u need this?select datepart(wk,getdate()) as Week_of_the_year,datepart(dy,getdate())as day_of_the_year,datepart(dy,getdate())+(7-datepart(dw,getdate()))-6 as start_day_of_the_week,datepart(dy,getdate())+(7-datepart(dw,getdate())) as end_day_of_the_weekSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
|
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-07-19 : 04:41:45
|
| [code] Select dateadd(wk,0,dateadd(wk,DATEDIFF(WK,0,getdate()),0))as startweek, dateadd(wk,1,dateadd(wk,DATEDIFF(WK,1,getdate()),0))-1 as endweek[/code]Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
kiranmurali
Yak Posting Veteran
55 Posts |
Posted - 2010-07-19 : 07:32:20
|
i want the week number of that particular date also.for example toaday is the start of 3rd week of this month.pls give sugeestions.quote: Originally posted by Idera
Select dateadd(wk,0,dateadd(wk,DATEDIFF(WK,0,getdate()),0))as startweek, dateadd(wk,1,dateadd(wk,DATEDIFF(WK,1,getdate()),0))-1 as endweek Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH
|
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-07-19 : 12:35:00
|
quote: Originally posted by kiranmurali i want the week number of that particular date also.for example toaday is the start of 3rd week of this month.pls give sugeestions.
Try thisSELECT Datepart(day, GETDATE() - 1) / 7 + 1Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
|
|
|
|
|