` Printed Icetips Article

Icetips Article



Par2: Week of year -- ISO 8601
2003-01-30 -- Paulo Theodoro
 
! Número da Semana - Padrao ISO 8601               Week Number - ISO 8601
Standard
    ! Semana começa na segunda                          Week start on Monday
    ! A primeira quinta sempre é da semana 1            First thursday
allways on first week
    ! 4 de Janeiro sempre é da semana 1                 January, 4 allways
on first week

    Week# = 0
    Day# = DAY(Datein)  ;  Month# = MONTH(Datein)  ;  Year# = YEAR(DateIn)
    First_Day# = (DATE(1,1,Year#) % 7) + 1
    IF First_Day# < 6
        NumOf_Days# = First_Day# + 4
    ELSE
        CASE First_Day#
        OF 6  ;  NumOf_Days# = 3
        OF 7  ;  NumOf_Days# = 4
        OF 1  ;  NumOf_Days# = 5
        END
    END
    Days_Year# = DATE(month#,day#,year#) - DATE(1,1,year#) + 1
    All_Days# = Days_Year# + NumOf_Days#
    Week# = INT(All_Days# / 7)
    IF Week# < 1
        CASE (DateIn % 7 + 1)
        OF 1  ;  Week# = NumeroSemana(DateIn - 3)
        OF 6  ;  Week# = NumeroSemana(DateIn - 1)
        OF 7  ;  Week# = NumeroSemana(DateIn - 2)
        OF 3 OROF 4 OROF 5  ;  Week# = 1
        ELSE  ;  Week# = 53
        END
    ELSIF Week# = 53
        IF DAY(DateIn) > 28 AND (DateIn % 7 + 1) = 2
            Week# = 1
        ELSIF DAY(DateIn) > 29 AND (DateIn % 7 + 1) = 3
            Week# = 1
        ELSIF DAY(DateIn) > 30 AND (DateIn % 7 + 1) = 4
            Week# = 1
        END
    END
    RETURN Week#



Printed November 23, 2024, 2:04 am
This article has been viewed/printed 35325 times.