data67 has asked for the wisdom of the Perl Monks concerning the following question:

I wastrying to use Date::Calc to figure out the first business day of the comming month. Any suggestions will be great. THANKS

Replies are listed 'Best First'.
Re: Business Date(s)
by merlyn (Sage) on Oct 17, 2001 at 19:14 UTC
    With the appropriate imports:
    # get first of next month: my @first_of_next_month = Add_Delta_YM((Today)[0,1], 1, 0, 1); # get day of week my $dow = Day_of_Week(@first_of_next_month); # if it's 1..5, then use it, else move forward: my @first_weekday_of_next_month = Add_Delta_Days(@first_of_next_month, + $dow == 7 ? 1 : $dow == 6 ? 2 : 0);

    -- Randal L. Schwartz, Perl hacker


    update: yes, this finds the first weekday of the next month; however, without further input, I decided that was what was meant by "first business day". Holidays will throw this off.
      I am using  use Date::Calc qw(:all);
      why do I see this error "Undefined subroutine &main::Add_Delta_YM called at".
      Do you mean Add_Delta_YMD() instead? I tried that but i get a "usage" error.
Re (tilly) 1: Business Date(s)
by tilly (Archbishop) on Oct 17, 2001 at 19:42 UTC
    If your concept of a business day is a week day, then merlyn's code will work.

    However if holidays matter to you, life is going to turn into a mess. The relevant holidays for a business depend on its country, state, city, and what industry it is in. Furthermore the definition of what the holidays will be for a given industry (eg stocks or bonds) is often only decided a few months in advance. This is particularly problematic when the holiday falls on a weekend, which weekday is a holiday? (I believe that the stock market changed its mind on how to handle Jan 1, 2000 fairly close to the date.) Also if you code a solution now and wait a few years, well the politicians will change what the holidays are so your perfectly good solution is now broken.

    Plus it varies by company. For instance two companies in the same city and industry may differ on whether they are taking the Friday after Thanksgiving as a holiday. Officially it is not. Unofficially, well that is a different story.

    In short, you have a simple-seeming request. But the more that you look into it, the more complex it will get, and there is no good generic solution. So my advice is to decide how important it is to get it right, and then decide on how you will maintain the holiday list going forward (because it will need maintainance). Either that or go with a known broken but mainly accurate solution like the one that merlyn gave.

Re: Business Date(s)
by princepawn (Parson) on Oct 17, 2001 at 22:11 UTC

      A nice theory, but it fails in this case. You link gives a "no such module" error

      Thanks,
      James Mastros,
      Just Another Perl Scribe