M
Morten Snedker
In Denmark the 1/1/2009 belongs to week 53 of year 2008.
The code below, as I believe should apply to Danish settings, returns
1, which is wrong.
Am I having a wrong approach?
'--code begin
Dim iWeek As Integer
Dim gc As New System.Globalization.GregorianCalendar
gc.CalendarType = Globalization.GregorianCalendarTypes.Localized
iWeek = gc.GetWeekOfYear(#1/1/2009#,
Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)
MsgBox(iWeek)
'-- code end --
I have a function for SQL-server that works perfectly, but is it
really necessary for such an ugly solution?
DECLARE @ISOweek varchar(10)
DECLARE @DATE datetime
DECLARE @s varchar(10)
DECLARE @Year int
SET @DATE='01-01-2009'
SET @ISOweek= CONVERT(varchar,DATEPART(wk,@DATE)+1
-DATEPART(wk,CAST(DATEPART(yy,@DATE) as CHAR(4))+'0104'))
--Special cases: Jan 1-3 may belong to the previous year
IF (@ISOweek='0')
SET
@ISOweek=CONVERT(varchar,dbo.ISOweek(CAST(DATEPART(yy,@DATE)-1
AS CHAR(4))+'12'+ CAST(24+DATEPART(DAY,@DATE) AS
CHAR(2)))+1)+','+CONVERT(varchar,YEAR(@DATE)-1)
--Special case: Dec 29-31 may belong to the next year
IF ((DATEPART(mm,@DATE)=12) AND
((DATEPART(dd,@DATE)-DATEPART(dw,@DATE))>= 28))
SET @ISOweek='1'
PRINT (@ISOweek)
Regards /Snedker
The code below, as I believe should apply to Danish settings, returns
1, which is wrong.
Am I having a wrong approach?
'--code begin
Dim iWeek As Integer
Dim gc As New System.Globalization.GregorianCalendar
gc.CalendarType = Globalization.GregorianCalendarTypes.Localized
iWeek = gc.GetWeekOfYear(#1/1/2009#,
Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)
MsgBox(iWeek)
'-- code end --
I have a function for SQL-server that works perfectly, but is it
really necessary for such an ugly solution?
DECLARE @ISOweek varchar(10)
DECLARE @DATE datetime
DECLARE @s varchar(10)
DECLARE @Year int
SET @DATE='01-01-2009'
SET @ISOweek= CONVERT(varchar,DATEPART(wk,@DATE)+1
-DATEPART(wk,CAST(DATEPART(yy,@DATE) as CHAR(4))+'0104'))
--Special cases: Jan 1-3 may belong to the previous year
IF (@ISOweek='0')
SET
@ISOweek=CONVERT(varchar,dbo.ISOweek(CAST(DATEPART(yy,@DATE)-1
AS CHAR(4))+'12'+ CAST(24+DATEPART(DAY,@DATE) AS
CHAR(2)))+1)+','+CONVERT(varchar,YEAR(@DATE)-1)
--Special case: Dec 29-31 may belong to the next year
IF ((DATEPART(mm,@DATE)=12) AND
((DATEPART(dd,@DATE)-DATEPART(dw,@DATE))>= 28))
SET @ISOweek='1'
PRINT (@ISOweek)
Regards /Snedker