Hi All, I'm working on a script that will accept two dates and return all business days within that range. I have it working however, when a weekend is within the date range, it restarts on the Monday date only. I don't know how to fix this and am hoping tht somebody here can assist. This is my code:
my $start_date = param('start_date'); my $end_date = param('end_date'); print header; print "$start_date to $end_date <br>"; my $start_date_parsed=ParseDate($start_date); my $end_date_parsed=ParseDate($end_date); print "$start_date_parsed to $end_date_parsed <br><br>"; my $delta=Delta_Format(DateCalc($start_date_parsed,$end_date_pa +rsed),'',"%dv"); print "$delta delta-days<br />\n"; for my $day (0..$delta) { my $this_date=DateCalc($start_date_parsed, "+$day day"); my $this_date_formatted=UnixDate($this_date,"%m-%d-%Y"); next unless ( Date_IsWorkDay($this_date)); print "For-Day $day: $this_date_formatted<br />"; } print end_html;
This is what is output from the date range 8/1/2014-8/9/2014:

08/04/2014 to 08/09/2014
2014080400:00:00 to 2014080900:00:00

5 delta-days
For-Day 0: 08-04-2014
For-Day 1: 08-05-2014
For-Day 2: 08-06-2014
For-Day 3: 08-07-2014
For-Day 4: 08-08-2014

This is what happens if I include a weekend in the range, 8/1/2014-8/15/2014:

08/04/2014 to 08/15/2014
2014080400:00:00 to 2014081500:00:00

4 delta-days
For-Day 0: 08-04-2014
For-Day 1: 08-05-2014
For-Day 2: 08-06-2014
For-Day 3: 08-07-2014
For-Day 4: 08-08-2014

This is what I'm actually looking for, with an example date range of 8/1/2014-8/15/2014:

08/04/2014 to 08/15/2014
2014080400:00:00 to 2014081500:00:00

9 delta-days
For-Day 0: 08-04-2014
For-Day 1: 08-05-2014
For-Day 2: 08-06-2014
For-Day 3: 08-07-2014
For-Day 4: 08-08-2014
For-Day 5: 08-11-2014
For-Day 6: 08-12-2014
For-Day 7: 08-13-2014
For-Day 8: 08-14-2014
For-Day 9: 08-15-2014


In reply to Business Date Range Only by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.