Set first day of week to monday  
Author Message
unnir





PostPosted: Thu Oct 12 03:29:56 CDT 2006 Top

SQL Server Developer >> Set first day of week to monday

Hi.
I try this code:

SET DATEFIRST 1
UPDATE dbo.tbl_log SET
iweek= Datepart(ww,logdate)-- Exctract weeknumer into field

I want Monday to be the first day of the week, but the code above does not
help me out. For example October 8. is still caculated as week 41, but I
want it into week 40.

I know this is basic for some of you. Please help me out.

Kind regards

Mr. Smith

SQL Server161  
 
 
promaxcoq





PostPosted: Thu Oct 12 03:29:56 CDT 2006 Top

SQL Server Developer >> Set first day of week to monday You want to calculate ISO8601 Standart Week numbers. SQL calculates
american week numbers for weeknumbers.
If you want to calculate european week numbers you must to use my
getISOWeekNo function.
please consume rfc for ISO8601


---START OF SQL CODE ---
/*
Created : 19 April 2005 Murat BUDAK
Modified : 19 April 2005 Murat BUDAK
----------------------------------------------------------------------
parametrede belirtilen tarihin hangi haftaya ait oldugunun bilgisini
ISO 8601 kurallarina g=F6re verir.
Buna g=F6re Hafta pazartesinden baslar ve ilk 4 g=FCn e ait olan bu
hafta formatina g=F6re ise 1nci haftadir.
*/
CREATE FUNCTION dbo.GetISOWeekNo

RETURNS tinyint
AS
BEGIN











END
THEN




'-01-04')

'-01-04')

'-01-04')

'-01-04')

'-01-04')

END,

) / 7) + 1




'-01-04')

'-01-04')

'-01-04')

'-01-04')

'-01-04')

END
THEN 1
ELSE









END,
@gun
) / 7) + 1
END

END

---END OF SQL CODE ---

Mr. Smith yazdi:
> Hi.
> I try this code:
>
> SET DATEFIRST 1
> UPDATE dbo.tbl_log SET
> iweek=3D Datepart(ww,logdate)-- Exctract weeknumer into field
>
> I want Monday to be the first day of the week, but the code above does not
> help me out. For example October 8. is still caculated as week 41, but I
> want it into week 40.
>
> I know this is basic for some of you. Please help me out.
>=20
> Kind regards
>=20
> Mr. Smith

 
 
Uri





PostPosted: Thu Oct 12 03:34:27 CDT 2006 Top

SQL Server Developer >> Set first day of week to monday Hi



SELECT
@today AS today,

AS week_start_date,








> Hi.
> I try this code:
>
> SET DATEFIRST 1
> UPDATE dbo.tbl_log SET
> iweek= Datepart(ww,logdate)-- Exctract weeknumer into field
>
> I want Monday to be the first day of the week, but the code above does not
> help me out. For example October 8. is still caculated as week 41, but I
> want it into week 40.
>
> I know this is basic for some of you. Please help me out.
>
> Kind regards
>
> Mr. Smith
>


 
 
Mr





PostPosted: Thu Oct 12 06:23:46 CDT 2006 Top

SQL Server Developer >> Set first day of week to monday Thanks both of you!
It helped me out. In this case I found it most suitable to Uri's solution.

Kind regards
Mr. Smith



> Hi


>
> SELECT


> AS week_start_date,

>
>
>
>
>


>> Hi.
>> I try this code:
>>
>> SET DATEFIRST 1
>> UPDATE dbo.tbl_log SET
>> iweek= Datepart(ww,logdate)-- Exctract weeknumer into field
>>
>> I want Monday to be the first day of the week, but the code above does
>> not help me out. For example October 8. is still caculated as week 41,
>> but I want it into week 40.
>>
>> I know this is basic for some of you. Please help me out.
>>
>> Kind regards
>>
>> Mr. Smith
>>
>
>