Day of the week: Difference between revisions

m
→‎{{header|REXX}}: changed the version names. -- ~~~~
m (→‎{{header|REXX}}: changed the version names. -- ~~~~)
Line 1,789:
 
=={{header|REXX}}==
===versionusing 1DATE weekday===
<lang rexx>do year = 2008 to 2121
if date('w', year'1225', 's') = 'Sunday' then say year
end</lang>
===versionusing 2DATE base===
Alternative:
<lang rexx>do year = 2008 to 2121
if date('b', year'1225', 's') // 7 = 6 then say year
end</lang>
Output'''output''' from either:
 
Output from either:
<pre>2011
2016
Line 1,818 ⟶ 1,816:
2118</pre>
 
===versionDATE 3iso===
The extended DATE parameters (arguments 2 and 3) are only supported by the newer REXX interpreters.
<br>newer REXX interpreters.
<br><br>
Language note: the DATE built-in function always returns the day-of-week in English, no matter what the native language is in effect.
<lang rexx>/*REXX program displays which years December 25th falls on a Sunday. */
<br>no matter what the native language is in effect.
<lang rexx>
/*REXX program displays which years December 25th falls on a Sunday. */
 
parse arg start finish . /*get the start and finish years.*/
if start=='' then start=2008 /*None specified? Assume default*/
Line 1,838 ⟶ 1,832:
 
say 'December 25th,' y "falls on a Sunday."
end /*y*/</lang>
'''output''' when using the default input
</lang>
Output (using the defaults):
<pre style="height:15ex;overflow:scroll">
December 25th, 2011 falls on a Sunday.
Line 1,861 ⟶ 1,854:
</pre>
 
===versionold school DOW 4===
This DOW (day-of-week) version will work with any version of a REXX interpreter.
<lang rexx>/*REXX program (old school) displays which years 12/25 falls on a Sunday*//
<lang rexx>
/*REXX program (old school) displays which years 12/25 falls on a Sunday*//
 
parse arg start finish . /*get the start and finish years.*/
Line 1,872 ⟶ 1,864:
do y=start to finish /*process the years specified. */
if dow(12,25,y)==1 then say 'December 25th,' y "falls on a Sunday."
end /*y*/
 
exit
 
/*─────────────────────────────────────DOW (day of week) subroutine─────*/
dow: procedure; arg m,d,y; if m<3 then do; m=m+12; y=y-1; end
yL=left(y,2); yr=right(y,2); w=(d + (m+1)*26%10+yr+yr%4+yL%4+5*yL) // 7
if w==0 then w=7; return w /*Sunday=1, Monday=2, ... Saturday=7*/</lang>
'''output''' using the default input
</lang>
Output (using the defaults):
<pre style="height:15ex;overflow:scroll">
December 25th, 2011 falls on a Sunday.