0

i have 3 parameters of date "Sep 30 Mon" (Month,DayNumber,Day), and i want to make a shell script that shows the quantity of days left to reach to Sep 30 Mon.

How can i do it?

2
  • 1
    Something like this? stackoverflow.com/questions/6282059/… Feb 7, 2019 at 20:07
  • Hello, yes, something like that, but how can i replace 2011/11/1 to Sep 30 Mon ? echo $(expr '(' $(date -d 2011/11/1 +%s) - $(date +%s) + 86399 ')' / 86400) " days until deadline" Feb 7, 2019 at 20:29

1 Answer 1

0

I am assuming you want to calculate the number of days until the closest day which will happen to be September 30 on Monday, be it any year. this script works for me (you can change the "Monday" in the condition to another day of week, same with other days/months. The script defines which year it is right now and counts from there. It uses the one-liner from the link to the stack-overflow thread under your question

YEAR=$(date +%Y)
DAY=$(date -d "30 SEP $YEAR" +%A)

until [[ $DAY == "Monday" ]]
do
YEAR=$(($YEAR+1))
DAY=$(date -d "30 SEP $YEAR" +%A)
done

echo $(expr '(' $(date -d $YEAR/9/30 +%s) - $(date +%s) + 86399 ')' / 86400) " days until deadline"
0

Not the answer you're looking for? Browse other questions tagged .