week

Prev Next

Function Names

week

Description

This function calculates the week number from the date. -1 is returned if the input parameter contains no recognizable date.

Vectorization: This function supports vectorization in the 1st function parameter. Instead of providing a single value, you can provide a set or even a nested set which contain multiple values. The function will then process every value and its return value contains a corresponding set containing all results.

Call as: function

Restrictions

Indirect parameter passing is disabled
Vectorization is allowed in the 1st function parameter

Parameter count

1-2

Parameters

No.TypeDescription
1
input
date or string converted to date
set
Date

Value to extract as described above. Vectorization: Put multiple values into a (nested) set.

Opt. 2
input
numeral Option

0: ISO week number, 1..52 or 53, all weeks are 7 days long. In some years, week 1 begins in the last days in December. In some other years, week 53 may run into early January.
1: Modify week number. Week 53 in early January changes to 0. Week 1 in end of December changes to 53.
2: 2-digit year and week number (calculated according to option 1) as fraction of 100.
3: 4-digit year and week number (calculated according to option 1)as fraction of 100.
Other values: -1 is returned

Default value: 0

Return value

TypeDescription
numeral
set
week number

Returned value as described above. -1 returned if no appropriate date found. If vectorization is applied, then the function returns a set containing mulitple values.

Examples

               d[1] = { 31.12.2020, 31.12.2021, 31.12.2022 }; // still a string. week() converts to date
               d[2] = { 01.01.2020, 01.01.2021, 01.01.2022 };
               for (option[] = 0, option[] <= 4, option[]++)
               {
                       print( week( d[1]{0}, option[] ), " ", week( d[1]{1}, option[] ), " ", week( d[1]{2}, option[] ), "   " );
                       echo ( week( d[2]{0}, option[] ), " ", week( d[2]{1}, option[] ), " ", week( d[2]{2}, option[] ) );
               }

Output

53 52 52   1 53 52
53 52 52   1 0 0
20.53 21.52 22.52   20.01 21 22
2020.53 2021.52 2022.52   2020.01 2021 2022
-1 -1 -1   -1 -1 -1
Try it yourself: Open LIB_Function_week.b4p in B4P_Examples.zip. Decompress before use.