Anonymous user
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}}==
===
<lang rexx>do year = 2008 to 2121
if date('w', year'1225', 's') = 'Sunday' then say year
end</lang>
===
<lang rexx>do year = 2008 to 2121
if date('b', year'1225', 's') // 7 = 6 then say year
end</lang>
▲Output from either:
<pre>2011
2016
Line 1,818 ⟶ 1,816:
2118</pre>
===
The extended
<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. */▼
▲/*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
<pre style="height:15ex;overflow:scroll">
December 25th, 2011 falls on a Sunday.
Line 1,861 ⟶ 1,854:
</pre>
===
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*//▼
▲/*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
'''output''' using the default input
<pre style="height:15ex;overflow:scroll">
December 25th, 2011 falls on a Sunday.
|