💾 Archived View for jacksonchen666.com › posts › 2023-10-13 › 13-17-59 › index.gmi captured on 2024-08-31 at 11:54:27. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-02-05)
-=-=-=-=-=-=-
2023-10-13 13:17:59Z (last updated 2024-01-22 20:59:34Z)
Today is Friday the 13th. The date on the calendar is the 13th, the weekday currently is Friday. It is something special (although I cannot recall right now why).
Then I wondered: When is the next Friday the 13th? And most importantly, how do I calculate that in my terminal?
dateutils is a bunch of programs which have to do with dates and timezones. There's manipulation and comparison programs, just a wide variety of Unix-like tools for dates.
I regularly use it for calculating some dates. However, I wanted to do something new to me: From date to weekday.
We want the weekday because we need it to be Friday. Thursday the 13th isn't going to cut it.
After reading the man page a little bit, I came up with this:
dateconv -f %A
%A is the weekday, so it will output "Friday" for 2023-10-13. So how do we find out which month has Friday the 13th?
With some shell stuff, here's the thing I came up with:
for i in {2023..2050}-{01..12}-13; do dateconv -f %A "$i" | grep "Friday" > /dev/null 2>&1 && echo $i; done
Uh, that's not exactly beginner friendly. I'm going to give a subset in a simpler form:
dateconv -f %A "2023-01-13" | grep "Friday" && echo "yes: 2023-01-13"
There. Basically, run that, and it will say "yes" when 2023-01-13 is Friday the 13th (hint: it is).
So I put that check into a loop like this:
for i in {2023..2050}-{01..12}-13; do dateconv -f %A "$i" | grep "Friday" > /dev/null 2>&1 && echo $i; done
That loop will check every month from year 2023 to year 2050 (inclusive) to see whether some month has Friday the 13th.
Here's a snippet of the output:
2023-01-13 2023-10-13 2024-09-13 2024-12-13 2025-06-13 2026-02-13 2026-03-13 2026-11-13
The rest of it I did not include, because there's a lot of answers. You can find more by running those commands, given you have dateutils installed.
So, we want October, and Friday the 13th. Here's the easy part: Changing the month to be always October. Like this:
for i in {2023..2050}-10-13; do dateconv -f %A "$i" | grep "Friday" > /dev/null 2>&1 && echo $i; done
The answer to the question is:
2023-10-13 2028-10-13 2034-10-13 2045-10-13
Those are all the Octobers which have Friday the 13th (until 2050).
I also wanted to show the usefulness of dateutils and qalc:
$ datediff 2023-10-13 2028-10-13 1827 $ qalc 1827 days 1827 days = 157852800 s $ qalc 1827 days to years 1827 days ≈ 5.002053388 yr
Ummm... ignore the imperfect number. It's 5 years.
for i in {2023..2050}-{01..12}-13; do dateconv -f %A "$i" | grep "Friday" > /dev/null 2>&1 && { dateconv -f %G $i; }; done | uniq -c | sort -n
Yeah it gets quite complicated...
uniq is used to count how many lines are the same, and sort to sort the result of uniq. dateconv is also used to get the year.
Results are: Majority of the years have 1 or 2 occurrences, but some years may have 3 occurrences of such.
I don't know. I feel like bruteforcing that answer isn't feasible, or it might not even be possible.
If someone knows how to do it and also has the answer on whether it is possible to have Friday the 13th occur 4 or more times in a year, maybe tell me!