3 And InputDateOffset > 1 Then YearInQuestion = YearInQuestion - 1 End If ' If the input date is after the 28th of December and the year ends with ' a monday, tuesday or wednesday, then the week belongs to the following year ' if the entered date is not a saturday or sunday If Month( inputdate ) = 12 And Day( inputdate ) > 28 And December31Offset < 3 And InputDateOffset < 5 Then YearInQuestion = YearInQuestion + 1 End If ' The 4th of January defines week #1 January4 = Datenumber (YearInQuestion , 1 , 4) ' Offset to the monday of week #1 diff=January4 - CalculateIsoWeekday( January4 ) FirstMondayOfYear = Cdat(diff) ' The time range between the monday of week #1 and the monday ' of the week in question is divided by 7, plus 1 for the first week weeknum = ( inputdate - InputDateOffset - FirstMondayOfYear ) \ 7 + 1 ' The return value is a string with the week number and the year GetCalendarWeek = weeknum End Function Function CalculateIsoWeekday( tmpdate As Variant ) As Integer %REM This function converts the weekday-numbers from the standard function to an offset acc. to the ISO version monday -> 0, ... , sunday -> 6 %END REM Dim n As Integer n = Weekday( tmpdate ) If n = 1 Then ' sunday to end of week n = n + 7 End If CalculateIsoWeekday = n - 2 End Function Ciao">
> |  
re : calcoli con le date
SSA-MN
C\'è una funzione nota in giro nel web che si chiama CalculateISOWeekday.

In ogni caso calcolare la data del primo lunedì dell\'anno è piuttosto semplice in quanto ti serve una variabile NotesDateTime e un ciclo While che vada avanti finchè Weekday(NotesDateTime.LSLocalTime) non è uguale al giorno che ti serve.

Per la funzione sopra citata ti riporto qui il sorgente. Sono due funzioni, io le gestisco in una libreria. Devi richiamare CalculateISOWeekday e passarle una data.

Function GetCalendarWeek(Byval inputdate As Variant ) As Integer
%REM
This function calculates the calendar week number
(ISO standard) for a given date value. The format
function of LotusScript (parameter "ww") does not solve
this problem.

Monday is the first day of the week. Week #1 is the week
that contains the 4th of January (ISO 8601). The week at the
end/beginning of the year belongs to the next/previous year,
if there are 3 days or less of that week in the year in question.
%END REM

Dim InputDateOffset As Integer
Dim YearInQuestion As Integer
Dim January4 As Variant
Dim January4Offset As Integer
Dim FirstMondayOfYear As Variant
Dim January1Offset As Integer
Dim December31Offset As Integer
Dim weeknum As Integer

\' The year value is preset with that of the input date
YearInQuestion = Year( inputdate )

\' Calculate offset to monday from the input date
InputDateOffset = CalculateIsoWeekday( inputdate )

\' Calculate offsets for the first/last day of the year
January1Offset = CalculateIsoWeekday(Datenumber (YearInQuestion , 1 , 1))
December31Offset = CalculateIsoWeekday( Datenumber (YearInQuestion , 12 , 31))

\' If the input date is before the 4th of January and the year starts with
\' a friday, saturday or sunday, the week belongs to the previous year
\' if the entered date is not a monday or tuesday
If Month( inputdate ) = 1 And Day( inputdate ) < 4 And January1Offset> 3 And InputDateOffset > 1 Then
YearInQuestion = YearInQuestion - 1
End If

\' If the input date is after the 28th of December and the year ends with
\' a monday, tuesday or wednesday, then the week belongs to the following year
\' if the entered date is not a saturday or sunday
If Month( inputdate ) = 12 And Day( inputdate ) > 28 And December31Offset < 3 And InputDateOffset < 5 Then
YearInQuestion = YearInQuestion + 1
End If

\' The 4th of January defines week #1
January4 = Datenumber (YearInQuestion , 1 , 4)

\' Offset to the monday of week #1
diff=January4 - CalculateIsoWeekday( January4 )
FirstMondayOfYear = Cdat(diff)

\' The time range between the monday of week #1 and the monday
\' of the week in question is divided by 7, plus 1 for the first week
weeknum = ( inputdate - InputDateOffset - FirstMondayOfYear ) \ 7 + 1

\' The return value is a string with the week number and the year
GetCalendarWeek = weeknum

End Function

Function CalculateIsoWeekday( tmpdate As Variant ) As Integer

%REM
This function converts the weekday-numbers from the
standard function to an offset acc. to the ISO version
monday -> 0, ... , sunday -> 6
%END REM

Dim n As Integer

n = Weekday( tmpdate )

If n = 1 Then \' sunday to end of week
n = n + 7
End If

CalculateIsoWeekday = n - 2

End Function


Ciao




calcoli con le date - attila -
    You are here re : calcoli con le date - SSA-MN -
        re... : calcoli con le date - attila -