Newsgroups: comp.unix.shell Date: Thu, 13 Oct 2005 16:17:51 +0200
> Hi, I need an algorightm (using bash script) to calculate next business > day (in mm/dd/yyyy format). I'm not worried about Thanksgiving, > Christmas etc. I just need to find out next business day so that it > falls between Monday and Friday, given today.
with GNU date and bash:
d=1 while (($(date -d "$d days" +%u) >= 6)); do ((++d)); done date -d "$d days" +%d/%m/%Y
Steffen Schuler
> I just need to find out next business day so that it > falls between Monday and Friday, given today.
[ $(LC_ALL=C date +%u) -gt 5 ] && echo "no work tomorrow" || echo "work tomorrow :-("
May be a way. Hoping more portable then GNU date and GNU bash. Setting LC_ALL should not be neccesary.
> Hi, I need an algorightm (using bash script) to calculate next business > day (in mm/dd/yyyy format).
All scripts I use take the date in YYYY-MM-DD format. It's easy enough to convert to your illogical format when you're finished.
Basically:
while : do case $dow in [12345]) break ;; *) get_tomorrow ## Use a function or GNU date get_dow $date ## Functions available; see below ;; esac done echo $date ## Format according to taste
> I'm not worried about Thanksgiving, Christmas etc. I just need to > find out next business day so that it falls between Monday and > Friday, given today.
For information on date arithmetic, see the comp.unix.shell FAQ <http://home.comcast.net/~j.p.h/cus-faq.html#6>, or see Chapter 8 of my book (see my .sig for the URL; that chapter is available on-line).
Chris F.A. Johnson <http://cfaj.freeshell.org> ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress <http://www.torfree.net/~chris/books/cfaj/ssr.html>