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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 function related query

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_week

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

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 EXAMPLE
TODAY IS 19/07/2010
WEEK START SHOULD DISPLAY 19
END OF THE WEEK 25 THAT IS COMING SUNDAY

THANKS IN ADVANCE
KIRAN
quote:
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_week

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/


Go to Top of Page

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
Go to Top of Page

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

Go to Top of Page

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 this

SELECT Datepart(day, GETDATE() - 1) / 7 + 1


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page
   

- Advertisement -