0

I want to find a date that is 57 –working– days after an arbitrary date using date or bash. For instance,

  1. today is august 21st,
  2. reference date is july 15th,
  3. what days will be 57 working days after july 15th?
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178

2 Answers2

2

This should work to just get all days

date -d '7/15/14 +57 days'

To get number of work days (M..F) you can do something lazy like this

#!/bin/bash
days=0
for ((i=1;i>0;i++)) do
  future=$(date -d "7/15/14 +$i days" '+%w')
  ((future!=0 && future!=6)) && ((days++))  # ignore sunday (0) and saturday (6)
  ((days==57)) && date -d "7/15/14 +$i days" && break
done

e.g.

> ./abovescript
> Thu Oct  2 00:00:00 CDT 2014
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
Reinstate Monica Please
  • 11,123
  • 3
  • 27
  • 48
0

Weird solution:

day=21
mon=8
year=2014
days=4

curl -s "http://www.timeanddate.com/scripts/dateserver.php?mode=addweekdays&d1=$day&m1=$mon&y1=$year&type=add&ad=$days&atyp=0&ach=3" | sed -n 's|.*<h2>Result: \(.*\)</h2>.*|\1|p'

prints

Wednesday, August 27, 2014

the date after 4 working days from 2014.08.21

for the

day=15
mon=7
year=2014
days=57

prints

Friday, October 3, 2014
clt60
  • 62,119
  • 17
  • 107
  • 194