weekday

Prev Next

Function Names

weekday

Description

Retrieves the weekday number from the date. If you need the weekday name, the use following function instead:
str( date[], "Tttt" );, possible with a 3rd parameter specifying the language.

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.

1
input
numeral Weekday calculation variant

1: 1 = Sunday, 2 = Monday .. 7 = Saturday
2: 1 = Monday, 2 = Tuesday .. 7 = Sunday
3: 0 = Monday, 1 = Tuesday .. 6 = Sunday
All other values are treated as 2.

Default value: 2

Return value

TypeDescription
numeral Weekday number

-1 is returned if no recognizable date is provided.

Examples

      for all parameters( { date(today) .. date(today)+10, date("15:00:00") }, date[] )
      {
          echo( str( date[], "Ttt, DD.Mmm.YYYY: " ), weekday(date[], 1), " ",
                weekday(date[], 2), " ", weekday(date[], 3) );
      }

Output

Sun, 14.Jul.2024: 1 7 6
Mon, 15.Jul.2024: 2 1 0
Tue, 16.Jul.2024: 3 2 1
Wed, 17.Jul.2024: 4 3 2
Thu, 18.Jul.2024: 5 4 3
Fri, 19.Jul.2024: 6 5 4
Sat, 20.Jul.2024: 7 6 5
Sun, 21.Jul.2024: 1 7 6
Mon, 22.Jul.2024: 2 1 0
Tue, 23.Jul.2024: 3 2 1
Wed, 24.Jul.2024: 4 3 2
___, __.___.____: -1 -1 -1
Try it yourself: Open LIB_Function_weekday.b4p in B4P_Examples.zip. Decompress before use.