day_of_week
| Definition: | atom_string dow = day_of_week(object y, integer m=0, d=0, bool bAsText=false) |
| Description: |
y: a year such as 2022, or a result from date() or a timedate. m: a month 1..12, ignored/overidden if y is a sequence. d: a day 1..31, ignored/overidden if y is a sequence. bAsText: self explanatory, but should use a named parameter when y is a sequence. Returns an integer from 1 to 7 (Mon..Sun)1, or the text version of it, ie {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}[integer dow]
|
| pwa/p2js: | Supported. |
| Comments: |
Obviously this functionality is required as part of date(), and has been made available for general use.
if bAsText is true2, then y and m can be 0 and d 1..7, aka a date()[DT_DOW], for convenience. Note however that as per the third line of the examples you still need to explicitly provide a 0 rather than completely omit y. Not suitable for use with years prior to the introduction of the Gregorian calendar. Returns 0 if y < 1752. |
| Example: |
?day_of_week(2015,1,1) -- prints 4 (Thursday) ?day_of_week(2015,1,1,true) -- prints "Thursday" ?day_of_week(0,d:=4,bAsText:=true) -- prints "Thursday" ?day_of_week(date(),bAsText:=true) -- prints the current day You may also, performance considerations aside, feel that
if day_of_week(y,m,d,true)="Monday" then
-- or format_timedate(td,"Dddd")="Monday", or
-- day_of_week(0,0,td[DT_DOW],true)="Monday"
is clearer or otherwise makes debugging easier than the equivalent
if day_of_week(y,m,d)=1 then
-- (or td[DT_DOW]=1)
|
| Implementation: | See builtins\pdates.e (an autoinclude) for details of the actual implementation. |
| See Also: | date, time, format_timedate |