How to Get Week on perticular Date?

Dear All,

Suppose here is one date say 5 augest 2006.
I want to find the week on that month.
Means  5 augest comes in first week. so I have to display 1
Please guide me,

Thanks in advance,
Prathamesh.
someone_geniusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JMattiasCommented:
Hi,

write a udf/function that returns that for you.

Regards
/Mattias
someone_geniusAuthor Commented:
Dear JMattias ,

I am Oracle DBA so I don't know much more about SQL serever. I know in oracle that to use to_char so please explain me.
Mr_PeerapolCommented:
SELECT DATEPART(week, @your_date) - DATEPART(week, CONVERT(DATETIME, CONVERT(VARCHAR(6), @your_date, 112)+'01', 112)) + 1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Maximize Customer Retention with Superior Service

The IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more to help build customer satisfaction and retention.

JMattiasCommented:
Hi,

CREATE  FUNCTION [ owner_name. ] function_name
    ( [ { @parameter_name [AS] scalar_parameter_data_type [ = default ] } [ ,...n ] ] )

RETURNS scalar_return_data_type

[ WITH < function_option> [ [,] ...n] ]

[ AS ]

BEGIN
    function_body
    RETURN scalar_expression
END

Example:

CREATE FUNCTION Getweek  (@DATE datetime)
RETURNS int
AS
BEGIN
   DECLARE @Day int
   Declare @Week int
   SET @Day= Day(@DATE)
   if @Day <= 7
       set @Week = 1
   if @Day > 7 and @Day <= 14
    .
.
.
.
.
   RETURN(@week)
END


Something like that.

Regards
/Mattias
JMattiasCommented:
hi,

Any luck?

Regards
/Mattias
someone_geniusAuthor Commented:
Dear All,

Thanks for  ur useful feedback.
Now  I m closing this thread.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.