Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

first business day in a given month

Status
Not open for further replies.

Myqns

Programmer
Jul 28, 2004
23
GB
I am looking for checking whether it is the first and second business day(working day)in a given month. How do I do that?

Thanks
 
Hi,

assuming your business week starts on Monday and ends Friday then here is a potential solution for you:

Code:
use POSIX qw(mktime); # required for mktime function

# $mon is the month number (0-11)
# $ynum is year - 1900 (for 2004 enter 104)

$mday=1; # 1st
$mon=7; # August
$ynum=104; # 2004

$tstamp = mktime (0,0,0,$mday,$mon,$ynum);
$projected_time = localtime ($tstamp);
$month_day=substr $projected_time,0,3;

++$mday if $month_day eq "Sun";
$mday+=2 if $month_day eq "Sat";

$month_day eq "Mon" if $mday > 1;

print "\nFirst business day is ",$month_day," and is on day ",$mday," of month";

This is a "very" hard-coded way of doing things however you can refine to suit your needs...
 
You're going to need to refer to a holiday database
Code:
sub check_holiday {
my %holidays;
my ($date)=@_;
  open (FH, "<holidays.txt");
  while (<FH>) {
    chomp($_);
    $holidays{$_}=1;
  }
  if (exists $holiday{$date}) {
     return "Holiday";
  } else {
     return "Not a holiday";
  }
}
Code:
if ( check_holiday ($date_2_check) ne "Holiday") {
  #it's not a holiday

HTH
--Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Thanks every one. Parkers, I modified your code to suit my requirements.

 
How do I get the second business day based on Parkers code?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top