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.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1-2

Parameters

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

Value to check.

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 week number

-1 is returned if no recognizable date is provided or wrong option value is used.

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.