Find the last Sunday of each month: Difference between revisions

Content added Content deleted
Line 1,245: Line 1,245:
24 November
24 November
29 December</pre>
29 December</pre>

=={{header|Lasso}}==
Abstracted version of "last friday of each month". LiveCode dateItem item 7 is day of week. It is numbered 1 (Sunday) to 7 (Saturday).
<lang LiveCode>function lastDay yyyy, dayofweek
-- year,month num,day of month,hour in 24-hour time,minute,second,numeric day of week.
convert the long date to dateitems
put 1 into item 2 of it
put 1 into item 3 of it
put yyyy into item 1 of it
put it into startDate
convert startDate to dateItems
repeat with m = 1 to 12
put m into item 2 of startDate
repeat with d = 20 to 31
put d into item 3 of startDate
convert startDate to dateItems
-- 1 is Sunday through to 7 Saturday
if item 7 of startDate is dayofweek and item 1 of startDate is yyyy and item 2 of startDate is m then
put item 3 of startDate into mydays[item 2 of startDate]
end if
end repeat
end repeat
combine mydays using cr and space
sort mydays ascending numeric
return mydays
end lastDay</lang>Example<lang LiveCode>put lastDay(2013, 1)</lang>Output<pre>1 27
2 24
3 31
4 28
5 26
6 30
7 28
8 25
9 29
10 27
11 24
12 29</pre>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==