User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 391,549 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,536 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 2442 | Replies: 1
Reply
Join Date: Sep 2006
Posts: 1
Reputation: BenK is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
BenK BenK is offline Offline
Newbie Poster

Help Week function help

  #1  
Sep 22nd, 2006
Hi,

I need a view with weeknumbers according to ISO. This means 1-1-2006 is week 53.
Now I created a function:

[MS SQL] CREATE FUNCTION dbo.WOY
( @Date DATETIME )
RETURNS SMALLINT
AS
BEGIN
DECLARE @WEEK SMALLINT
IF DATEPART(dw, CAST('1-1-' + CAST(DATEPART(YYYY, @Date) AS VARCHAR) AS DATETIME)) > 4
IF DATEPART(ww, @Date) = 1
SET @WEEK = 53
ELSE SET @WEEK = DATEPART(ww, @Date) -1
ELSE SET @WEEK = DATEPART(ww, @Date)
RETURN ( @WEEK )
END[/MS SQL]

In a view I added a column WOY(Date)

Now I need somehow set the datefirst to 1 but how can I do that?

Anyone?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: El Paso, TX
Posts: 225
Reputation: extofer is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
extofer's Avatar
extofer extofer is offline Offline
Posting Whiz in Training

Re: Week function help

  #2  
Sep 22nd, 2006
I tried your function:

PRINT dbo.WOY(01/01/2006)

I got = 1
What do you mean set the datefirst to 1.
Are you implying that 1-1-2006 = week 1??
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MS SQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 9:12 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC