A
A
Alexander Fedoruk2018-01-25 02:38:47
bash
Alexander Fedoruk, 2018-01-25 02:38:47

How to determine the number of a given day of the week of a given year using bash date without loops?

Actually the question, I came up with a problem for myself when I was drunk, and for a week now she hasn’t let me go.
How to determine the number of a given day of the week of a year using bash date without loops?
For example, the script takes 2018 6 (the first Sunday of 2018) and outputs 6 (the sixth number).
Takes 2003 3 (the first Thursday of 2003) and outputs 2 (the second number).
Why no cycles?

Because I am a freak
Because that's how I came up with it.
It seemed to sound just like two fingers on the asphalt, and then he sat and turned gray.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel K, 2018-01-25
@AlexSaFF

Um, the first Sunday seems to be the 7th...
In general, either I misunderstood, or you calculated something incorrectly.
Directly in the console:

year=2018
weekday=6 (суббота)
date -d "$year-01-01-$(date -d "$year--01-01" +%u)days+$weekday days +$((7*$(($year-$(date -d "$year-01-01-$(date -d "$year--01-01" +%u)days +$weekday days" +%Y ))))) days" +%d

At the output "06", i.e. first Saturday 2018)
Count: 1-Monday ...
It also works like this: weekday=6 (Saturday of the first week), weekday=13 (same Saturday, but the second week), 20 (Saturday of the third week), etc.
You owe me my 15 minutes of my life :DDD

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question