Article 647DR Day of the year

Day of the year

by
John
from John D. Cook on (#647DR)

It's necessary now and then to find the day of the year for a date. For example, today is 272nd day of 2022. How hard would it be to calculate the day of the year in your head?

Each month has about 30 days, so the dth day of the mth month is approximately day

30(m - 1) + d

of the year. So, for example, today is September 29, and the expression above would estimate today's day of the year as 269.

We could start with this approximation and refine it to be exact. The exact value to add to each day d is the cumulative number of days in the preceding months. This is the number in the middle column below. The difference between the exact value and the approximate value is in the third column.

 |-------+---------+------| | Month | yearday | diff | |-------+---------+------| | 1 | 0 | 0 | | 2 | 31 | 1 | | 3 | 59 | -1 | | 4 | 90 | 0 | | 5 | 120 | 0 | | 6 | 151 | 1 | | 7 | 181 | 1 | | 8 | 212 | 2 | | 9 | 243 | 3 | | 10 | 273 | 3 | | 11 | 304 | 4 | | 12 | 334 | 4 | |-------+---------+------|

So the exact expression would be

30(m - 1) + d + correction factor

Of course you'd have to add 1 in leap years for months past February.

The hardest part of calculating the year-day would be memorizing the correction factor third column above. I can remember these numbers, but I haven't come up with a way that I'd recommend to anyone else.

It's typically much easier to memorize something than to come up with a mnemonic that other people would find acceptable. No matter how natural your mnemonics sound to you, they usually sounds like nonsense to anyone else.

The post Day of the year first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments