Hello packetstormer,

An alternative solution to your problem could be to the use of Date::Manip module.

The module is very very powerful and with simple use of ""business" you can choose to only calculate the days that are business days and not holidays/weekends.

Business day for the module is considered 08:00am - 05:00pm (9 hours / 1 hour lunch). Sample of code below:

#!/usr/bin/perl use strict; use warnings; use Date::Manip; my $date_1 = "November 24 2017 4:59pm"; my $date_2 = "November 27 2017 08:01am"; my $sec = Delta_Format(DateCalc($date_1, $date_2, "business"), 0, "%st +"); printf "diff secs: %d\n", $sec; __END__ $ perl sample.pl diff secs: 120

More information regarding the functions you can find here Date::Manip::DM5. If for any reason you want to change the hours/days you can do it through Date::Manip::Config/BUSINESS CONFIGURATION VARIABLES.

Update: Adding the Mode "business" explanation. The third parameter that you can add on the DateCalc function is $mode. This parameter when you do date calculations can take 6 different options. Sample from the documentation:

exact : an exact, non-business calculation semi : a semi-exact, non-business calculation approx : an approximate, non-business calculation business : an exact, business calculation bsemi : a semi-exact, business calculation bapprox : an approximate, business calculation

For more information you can read the official documentation Date::Manip::Calc/MODE.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Calculate seconds between dates by thanos1983
in thread Calculate seconds between dates by packetstormer

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.