ChatGPT and calendars

I’m working on an algorithm to determine the dates of holidays, for example, Labor Day is the 1st Monday in September (thus September 2 for 2024… anywhere from the 1st through the 7th depending on the year). Just a little hack that I felt like doing. Well, it’s slightly complex, so just for fun I decided to ask ChatGPT how to do it.

ChatGPT did an excellent job… but the (my bolding) warning at the end was a surprise:

Me: How do I calculate which day of the month is, for example, the third Thursday?

ChatGPT:

To calculate which day of the month is, for example, the third Thursday, you can follow these steps:

1. Determine which day of the week the first day of the month falls on.

2. Find the day of the week that corresponds to the desired weekday (e.g., Thursday).

3. Add the appropriate number of days to the first occurrence of that weekday in the month to find the desired occurrence (e.g., third Thursday).

Here’s a more detailed breakdown:

1. Find the day of the week for the first day of the month using any method (e.g., a calendar, programming libraries like Python’s `datetime` module).

2. Determine the difference in days between the desired weekday and the day of the week of the first day of the month.

3. Calculate how many days you need to add to the first occurrence of the desired weekday to reach the desired occurrence (e.g., third Thursday).

For example, if the first day of the month is a Monday and you’re looking for the third Thursday, you’d add 4 days (Thursday minus Monday) to the date of the first Monday to find the date of the first Thursday. Then, you’d add (3 – 1) * 7 days to find the date of the third Thursday.

Keep in mind that this calculation might involve considerations for leap years and edge cases where the month doesn’t have the desired occurrence of the weekday (e.g., if there are only two Thursdays in the month).

And more good news from FutureCrunch (now Fix the News):

Humanity sees significant decline in tetanus-related fatalities

Tetanus, a bacterial infection that causes paralysis and can be fatal, claimed over 250,000 lives annually in the early 1990s. By 2019, the number of deaths had plummeted to fewer than 35,000 per year—largely thanks to widespread administration of the combined diphtheria, tetanus, and pertussis vaccines. OWD

Leave a comment