Link to home
Start Free TrialLog in
Avatar of someone_genius
someone_genius

asked on

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.
Avatar of JMattias
JMattias
Flag of Sweden image

Hi,

write a udf/function that returns that for you.

Regards
/Mattias
Avatar of someone_genius
someone_genius

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Mr_Peerapol
Mr_Peerapol

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
hi,

Any luck?

Regards
/Mattias
Dear All,

Thanks for  ur useful feedback.
Now  I m closing this thread.