This is a short snippet to calculate the next business day. It takes into account a holiday metric of days to skip past, as well. Admittedly, this is probably more complicated than it needs to be, and if anyone would care to golf it, I'd love to see the input on how to make it shorter/faster/more efficient.
#!/usr/local/bin/perl -w # Calculate the next business day taking into account a # holiday metric. use strict; my $next_business_day = _calc_next_date(); print "Next business day: $next_business_day\n"; sub _calc_next_date { use POSIX qw(strftime); # Set up the holiday metric -- skip past these dates. my @_holiday = ('01/01', '01/21', '03/29', '05/27', '07/04', '09/02', '10/28', '10/29', '12/24', '12/25'); my $_today = `date +"%m/%d"`; chomp($_today); my $_today_day = `date +"%a"`; chomp($_today_day); my $_good_date = 0; my $_next_date; my $_amount = 0; # Loop until we get a weekday that isn't in the holiday metric. until ($_good_date) { if ($_today_day eq 'Fri') { $_amount += 259200; } else { $_amount += 86400; } $_next_date = strftime "%m/%d", localtime(time + $_amount); foreach (@_holiday) { if ($_ eq $_next_date) { $_amount = $_amount + 86400; } } $_next_date = strftime "%m/%d", localtime(time + $_amount); my $_next_day = strftime "%a", localtime(time + $_amount); if (($_next_day ne 'Sat') && ($_next_day ne 'Sun')) { $_good_date = 1; foreach (@_holiday) { if ($_ eq $_next_date) { $_good_date = 0; } } } } $_next_date = strftime "%m/%d/%y", localtime(time + $_amount); return $_next_date; }

Replies are listed 'Best First'.
Re: Next business day.
by TStanley (Canon) on Sep 11, 2002 at 16:43 UTC
    Or you can use Date::Business

    TStanley
    --------
    It is God's job to forgive Osama Bin Laden. It is our job to arrange the meeting -- General Norman Schwartzkopf
Re: Next business day.
by RMGir (Prior) on Sep 11, 2002 at 17:11 UTC
    Nice one, ++!

    This is a feature of Date::Manip, as well.

    Of course, just about anything you can do to Dates (of the calendar kind) is a feature of Date::Manip...
    --
    Mike