dayofweek()

Learn how to use the dayofweek() function to return the timespan since the preceding Sunday.

Provides the number of days since the preceding Sunday, as a timespan.

To convert timespan to int, see Convert timespan to integer.

Syntax

dayofweek(date)

Parameters

NameTypeRequiredDescription
datedatetime✔️The datetime for which to determine the day of week.

Returns

Returns the timespan since midnight at the beginning of the preceding Sunday, rounded down to an integer number of days.

Examples

The follow example shows how to extract the day of the week from a specified datetime value.

print
Timespan = dayofweek(datetime(1947-11-30 10:00:05))

Output

Timespan
00:00:00

The following example returns 1, indicating that the specified datetime is a Monday.

print
Timespan = dayofweek(datetime(1970-05-11))

Output

Timespan
1.00:00:00

Convert timespan to integer

The following example returns the number of days both as a timespan and as data type int.

let dow=dayofweek(datetime(1970-5-12));
print Timespan = dow, Integer = toint(dow/1d)

Output

TimespanInteger
2.00:00:002