week  
Author Message
Kake





PostPosted: Sun Feb 12 10:02:48 CST 2006 Top

SQL Server Developer >> week

I've some installations of SQLEXPRESS and i've found one that wrong to
calculate week from a date.
This is the code:
PRINT DATEPART(week, CAST('20060217' AS DATETIME))

The right week is 7 but one server say me 8

Someone have an idea why ??

MM

SQL Server163  
 
 
MarkWilliams





PostPosted: Sun Feb 12 10:02:48 CST 2006 Top

SQL Server Developer >> week The value that DATEPART(week, '20060217') will return depends on the value of
@@DATEFIRST, which specifies which day of the week is marks the boundary
between weeks.

The U.S. English default is 7, which means Sunday is the first day of the
week. If you are getting different values for DATEPART(week, '20060217') on


--




> I've some installations of SQLEXPRESS and i've found one that wrong to
> calculate week from a date.
> This is the code:
> PRINT DATEPART(week, CAST('20060217' AS DATETIME))
>
> The right week is 7 but one server say me 8
>
> Someone have an idea why ??
>
> MM
>
>
>
 
 
Tibor





PostPosted: Sun Feb 12 10:15:16 CST 2006 Top

SQL Server Developer >> week In addition, SQL Server never calculated week number the same way as "the rest of the word" and also
the way that the ISO standard specifies. Use the ISOWeek function, found in Books Online or a
calendar table instead of the DATEPART function.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/




> The value that DATEPART(week, '20060217') will return depends on the value of

> between weeks.
>
> The U.S. English default is 7, which means Sunday is the first day of the
> week. If you are getting different values for DATEPART(week, '20060217') on

>
> --
>
>

>
>> I've some installations of SQLEXPRESS and i've found one that wrong to
>> calculate week from a date.
>> This is the code:
>> PRINT DATEPART(week, CAST('20060217' AS DATETIME))
>>
>> The right week is 7 but one server say me 8
>>
>> Someone have an idea why ??
>>
>> MM
>>
>>
>>

 
 
Mauro





PostPosted: Sun Feb 12 10:24:46 CST 2006 Top

SQL Server Developer >> week Ok but i don't understand why same SO, same SQLExpresse, same code, same
data & different result !!

thanks

mauro



> In addition, SQL Server never calculated week number the same way as "the
> rest of the word" and also the way that the ISO standard specifies. Use
> the ISOWeek function, found in Books Online or a calendar table instead of
> the DATEPART function.


 
 
Tibor





PostPosted: Sun Feb 12 10:31:47 CST 2006 Top

SQL Server Developer >> week DAEFIRST is inherited from the language you have specified for your login. Try below and you will
see that different languages has different default DATEFIRST:

EXEC sp_helplanguage

But in any case, if you expect to even find Jan 1 to be week number 52 (as we do in Europe, don't
use DATEPART.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/



> Ok but i don't understand why same SO, same SQLExpresse, same code, same data & different result
> !!
>
> thanks
>
> mauro
>


>> In addition, SQL Server never calculated week number the same way as "the rest of the word" and
>> also the way that the ISO standard specifies. Use the ISOWeek function, found in Books Online or
>> a calendar table instead of the DATEPART function.
>
>

 
 
Henri





PostPosted: Sun Feb 12 13:07:28 CST 2006 Top

SQL Server Developer >> week For europe weeks use:


AS
BEGIN














-- Julianische Tagesnummer berechnen
-- erster Tag = 01.01.-4713, letzter Tag = 22.01.3268



@Tag - 32075
-- daraus KW berechnen







END


--
with greetings from Spöck




> DAEFIRST is inherited from the language you have specified for your login. Try below and you will
> see that different languages has different default DATEFIRST:
>
> EXEC sp_helplanguage
>
> But in any case, if you expect to even find Jan 1 to be week number 52 (as we do in Europe, don't
> use DATEPART.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
>

> > Ok but i don't understand why same SO, same SQLExpresse, same code, same data & different result
> > !!
> >
> > thanks
> >
> > mauro
> >


> >> In addition, SQL Server never calculated week number the same way as "the rest of the word" and
> >> also the way that the ISO standard specifies. Use the ISOWeek function, found in Books Online or
> >> a calendar table instead of the DATEPART function.
> >
> >
>
>
 
 
--CELKO--





PostPosted: Sun Feb 12 19:00:16 CST 2006 Top

SQL Server Developer >> week Microsoft does not agree with the ISO rules. Do some research.