Ask Dave Taylor
  • Facebook
  • Instagram
  • Linkedin
  • Pinterest
  • Twitter
  • YouTube
  • Home
  • Videos
  • Most Popular
  • Top Categories
  • Books
  • About Dave
  • Ask Me
  • > Donate <
  • Home
  • Linux Shell Script Programming
  • On What Day Does New Year’s Day Usually Occur?

On What Day Does New Year’s Day Usually Occur?

December 29, 2017 / Dave Taylor / Linux Shell Script Programming / 1 Comment

I’ve been wondering whether New Year’s Day is more likely to occur on a weekday or weekend day. I mean, on a day by day basis. In other words, is it more likely to occur on a Wednesday or Saturday?

You hopefully realize that since there are five weekdays and two weekend days that New Year’s Eve – or any other calendar event that occurs on a specific date – is over twice as likely to occur on a weekday, right? 🙂 You do raise a fascinating question about the consistency of our calendar, however, and how it shifts over time – since 365 days / 7 isn’t evenly divisible – year after year. In theory, the odds of an event happening on any given day of the week should be exactly even over a long enough period, but it turns out that isn’t true!

Before we go any further, however, we have to compensate for the switch from the Julian calendar to the Gregorian calendar that we use today. That happened way back in 1582. October 1582, to be specific. That means the first “January 1st” on the modern calendar occurred in 1583. And that day turned out to be a Tuesday, as it happens.

Figuring out this question calls for some programming, actually, so let’s dig into a Linux shell script that can solve the problem. It all revolves around a handy little command line utility called cal that lets you specify a month and year and get a simple calendar listed. Like this:

linux cal calendar january 1583

Simple enough, right? This is where it gets interesting, though: if you evaluate the date of the last day of the first week of the year (in the above example, it’s 5) you can calculate what day of the week the first day occurred. Why go through that hoop? Because it turns out to be easier programmatically to get that last date than one in the middle of the line.

To do this, we’re going to build a loop that goes through a lot of years – 1583-3000 – and simply tallies up the day of the week that Jan 1 occurs. That’s done in a Bash (Linux) shell script thusly:

year1=1583;  yearN=3000

for (( year=$year1; year <= $yearN; year++));
do
some code goes here
done

Fairly straightforward: Start by setting the year to $year1, which is 1583, then keep looping and incrementing by one until we hit $yearN.

The question is: what happens in the middle? There are three steps required to figure out the day of the week for a given calendar. First, isolate just the first week of the calendar, which can be done either by simply extracting line two, or identifying the line that has “1” by itself. I opt for the latter because it’ll work even if the cal output might change. In Linux scripting terms, it looks like this:

firstweek=”$(cal 1 $year | $grep “( 1 | 1$)”)”

Once that line’s extracted, we reverse it with the rev command so what was the last digit on the line becomes the first, then use cut to extract it:

lastday=”$(echo $firstweek|rev|cut -c1)”

Now if we know the numeric day of Saturday of the first week of the new year, we can easily figure out which day the 1st was on. So let’s tally it up!

case $lastday in
1 ) (( sat += 1 )); day=”Saturday”; ;;
2 ) (( fri += 1 )); day=”Friday”; ;;
3 ) (( thu += 1 )); day=”Thursday”; ;;
4 ) (( wed += 1 )); day=”Wednesday”; ;;
5 ) (( tue += 1 )); day=”Tuesday”; ;;
6 ) (( mon += 1 )); day=”Monday”; ;;
7 ) (( sun += 1 )); day=”Sunday”; ;;
esac

That’s all the work, believe it or not. Remember, if the last day of the first week is a 5, for example (as shown earlier), then the 1st must be on a Tuesday, so the code increments the variable “tue” one as appropriate.

If we run this script up thru 2020, it reports this:

438 years analyzed, starting with 1583. Results: Sunday = 63, Monday = 62, Tuesday = 65, Wednesday = 64, Thursday = 62, Friday = 62 and Saturday = 60.

That’s quite interesting results, actually. Saturday was the least common day for a New Year’s Day to occur on (60 times out of 438 years), while Tuesday proved the most common, occurring 65 times. Why? Darn good question.

Let’s run the test one more time, going all the way from 1583 to 3000. Surprisingly, the day by day results are the same:

1418 years analyzed, starting with 1583. Results: Sunday = 205, Monday = 199, Tuesday = 207, Wednesday = 203, Thursday = 202, Friday = 204 and Saturday = 198.

Interesting, isn’t it? And now you know. As to why that proves to be the case, I’ll leave that for you to figure out!

Let’s Stay In Touch!

Never miss a single article, review or tutorial here on AskDaveTaylor, sign up for my fun weekly newsletter!
Name: 
Your email address:*
Please enter all required fields
Correct invalid entries
No spam, ever. Promise. Powered by FeedBlitz
Please choose a color:
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!
calculate dates, calendar math, dates, gregorian calendar, julian calendar, new year's day

One comment on “On What Day Does New Year’s Day Usually Occur?”

  1. Bill Bidel says:
    January 3, 2018 at 1:57 pm

    It’s probably due to February having only every four years an extra day that screws with Tuesdays.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Recent Posts

  • Can I Have Microsoft Edge Suggest Strong Passwords?
  • How Can I Password Protect Tax Forms Sent Via Email?
  • Easy Way to Add Emoji to Tweets from a Web Browser?
  • How Do You Post Multiple Photos in Instagram?
  • How Can I Change the Default Search Engine in Google Chrome to Microsoft Bing?

On Our YouTube Channel

DIGDIY BUDGET ANC TWS Earbuds [D10WH] -- REVIEW

Rush Charge Hinged Smartphone Battery Stand -- UNBOXING & REVIEW

Categories

  • AdSense, AdWords and PPC Help (106)
  • Amazon Echo & Kindle Help (79)
  • Amazon, eBay and Online Shopping Help (157)
  • Android Help (158)
  • Apple Watch Help (49)
  • Articles, Tutorials and Reviews (326)
  • Business Advice (191)
  • Computer and Internet Basics (714)
  • d) None of the Above (160)
  • Facebook Help (364)
  • Google & Gmail Help (154)
  • HTML and Web Design (243)
  • Instagram Help (43)
  • iPad Help (136)
  • iPhone Help (570)
  • LinkedIn Help (79)
  • Linux Help (147)
  • Linux Shell Script Programming (86)
  • Mac & MacOS Help (830)
  • Most Popular (10)
  • MP3 Player Help (181)
  • Outlook & Office 365 Help (9)
  • PayPal Help (68)
  • Pinterest Help (53)
  • Reddit Help (11)
  • SEO & Marketing (80)
  • Spam, Scams & Security (82)
  • Trade Show Updates (23)
  • Twitter Help (212)
  • Video Game Tips (66)
  • Web Site Traffic Tips (62)
  • Windows 10 Help (825)
  • Wordpress Help (201)
  • Writing and Publishing (72)
  • YouTube Help (43)
  • YouTube Video Reviews (159)
  • Zoom, Skype & Video Chat Help (40)

Archives

Social Connections:

Ask Dave Taylor


Follow Me on Pinterest
Follow me on Twitter
Follow me on LinkedIn
Follow me on Instagram


AskDaveTaylor on Facebook



microsoft insider mvp


This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to our terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. Our lawyer says "Thanks for your cooperation."
© 2020 by Dave Taylor. "Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.
Privacy Policy - Terms and Conditions - Accessibility Policy