Post Reply 
(41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
01-24-2021, 05:00 AM
Post: #5
RE: (41CX/DM41)(17Bii) Date of the first Advent Sunday in a year
(08-10-2020 03:02 PM)ggauny@live.fr Wrote:  Instead of DDays I'm using DOW, but unfortunatly DOW gives 0 if the day is a sunday, (HP Prime gives 7).
So we have to "adjust" in case of DOW gives a 0.

No need to adjust, just shift the reference to Christmas Eve.
Better yet, reference to Dec 3, eliminated the need to subtract 21 days.

1st Advent Sunday = (Dec 3) - DOW(Dec 3) days       // Nov 27 to Dec 3

Code below assumed date format MM.DDYYYY
Code:
00 { 29-Byte Prgm }
01▸LBL "DIMAVEN"
02 1ᴇ6
03 ÷
04 12.03   ; Dec 3
05 +
06 ENTER
07 DOW
08 +/-
09 DATE+
10 END

Since DOW(Dec 3) = DOW(Dec 31), we can even do this in the head, using facts below:

1. Gregorian calendar repeat itself every 400 years.
2. DOW(Dec 31, 2000) = 0 (Sunday)
3. 365 days = 52 weeks + 1 day

Example, Year 2016:

2016 % 400 = 16
leap years count = IP(16/4) - IP(16/100) = 4
DOW(Dec 31, 2016) = (4 + 16) % 7 = 6

(Dec 3, 2016) - 6 days = Nov 27, 2016

Example, Year 2021:

2021 % 400 = 21
leap years count = IP(21/4) - IP(21/100) = 5
DOW(Dec 31, 2021) = (5 + 21) % 7 = 5

(Dec 3, 2021) - 5 days = Nov 28, 2021
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (41CX/DM41)(17Bii) Date of the first Advent Sunday in a year - Albert Chan - 01-24-2021 05:00 AM



User(s) browsing this thread: 1 Guest(s)