ASP.NET - semana del año

 
Vista:
sin imagen de perfil

semana del año

Publicado por Alfredo (35 intervenciones) el 25/06/2009 22:52:53
qué funcion debo utilizar en asp.net 2003 para obtener el numero de la semana del año.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

RE:semana del año

Publicado por ANTONIO (106 intervenciones) el 01/07/2009 12:42:12
MIRA A VER SI ESTE CODIGO QUE VI POR LA RED TE VALE DE ALGO SALUDOS

I'm from Norway and we use this standards:
First day of week:
Monday (complies with ISO standard 8601, section 3.17)
First week of year:
Week that has at least four days in the new year (complies with ISO standard 8601, section 3.17)

After this standards this function will return the week (as integer) when calling the function with a given date (as date).

It might not be the easiest code, but as far as I can tell it's working.

VB.Net Code:

Function FindWeek(ByVal dtmToday As Date) As Integer
Dim intThisYear, intThisMonth, x As Integer
Dim dtmFirstDayOfWeek, FirstDayOfYear As Date
Dim MytimeSpan As TimeSpan

' Find first day of week

Do While dtmToday.DayOfWeek <> 1
intThisYear = dtmToday.Year
intThisMonth = dtmToday.Month
MytimeSpan = dtmToday.Subtract(CDate(1 & "." & intThisMonth & "." & intThisYear))
x = MytimeSpan.Days.ToString
If x = 0 Then
If intThisMonth = 1 Then
intThisMonth = 13
intThisYear = intThisYear - 1
End If
x = DateTime.DaysInMonth(intThisYear, intThisMonth - 1)
dtmToday = CDate(x & "." & intThisMonth - 1 & "." & intThisYear)
Else
dtmToday = CDate(x & "." & intThisMonth & "." & intThisYear)
End If
Loop
dtmFirstDayOfWeek = dtmToday

'Find week of year from first day of week
FirstDayOfYear = CDate("01.01." & dtmFirstDayOfWeek.ToString("yyyy"))
x = 0
If FirstDayOfYear.DayOfWeek = 5 Or FirstDayOfYear.DayOfWeek = 6 Or FirstDayOfYear.DayOfWeek = 0 Then
For x = 0 To dtmFirstDayOfWeek.DayOfYear + 1
Next x
x = (x / 7)
Else
For x = 1 To dtmFirstDayOfWeek.DayOfYear
Next x
x = (x / 7) + 1
If dtmFirstDayOfWeek.Month = 12 Then
If dtmFirstDayOfWeek.Day = 29 Then x = 1
If dtmFirstDayOfWeek.Day = 30 Then x = 1
If dtmFirstDayOfWeek.Day = 31 Then x = 1
End If
End If
Return x
End Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar