Answer the question
In order to leave comments, you need to log in
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 freakBecause that's how I came up with it.
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question