in reply to DateManip Delta_Format Usage

I played around with this a bit and (without actually verifying the math) ended up with the following:
#!/usr/bin/perl use strict; use Date::Manip; my $start = Date::Manip::ParseDate('2013-10-03 00:00:00'); my $end = Date::Manip::ParseDate('2013-12-09 00:00:00'); print "$start\n"; print "$end\n"; #Standard Days my $standard_delta = Date::Manip::DateCalc($start,$end,1); print "$standard_delta\n"; my $standard_days = Date::Manip::Delta_Format($standard_delta,2,%dyd') +; print "$standard_days\n"; #Business Days my $business_delta = Date::Manip::DateCalc($start,$end,2); print "$business_delta\n"; my $business_days = Date::Manip::Delta_Format($business_delta,2,'%dyd' +); print "$business_days\n";
With output that looks like:
2013100300:00:00 2013120900:00:00 +0:2:+0:6:0:0:0 66.87375 +0:2:+0:+4:0:0:0 64.87375
Note: that I am using a newer version than you state that you are, but as close as I can tell from a cursory glance through the CPAN docs, the functionality has not changed. (I may be wrong about that, but it will only take a second to copy the above and try it. If I am wrong, you waste a copy/paste ->save->run amount of time, not much more...).

Hope that is helpful... Update: Changed format directive from '%dydt' to '%dyd', thus changing the output to exclude the 't' from the end of the calculated days.

...the majority is always wrong, and always the last to know about it...
Insanity: Doing the same thing over and over again and expecting different results.

Replies are listed 'Best First'.
Re^2: DateManip Delta_Format Usage
by SBECK (Chaplain) on Jan 13, 2014 at 18:05 UTC

    Sorry for the tardy reply... I don't get on perl monks more often than every few days.

    The original post doesn't include the version they are using which is unfortunate. I'm assuming that it's from the pre 6.00 era. The '%dyd' style formats are from the newer version of Date::Manip, so they won't work with a 5.xx era script.

    Also, the original post said he expected (not sure if it was good or bad) around 60+ days for both types of delta, and that shouldn't be a desired result since a business delta by definition is excluding a bunch of days (weekends) so it should be smaller by a factor of approximately 5/7.

    If I wanted to know how many days were in the deltas, I'd do the following:

    #Standard Days
    my $standard_delta = DateCalc($start,$end,0);
    my $standard_days  = Delta_Format($standard_delta,2,'%dt');
    print "$standard_delta :: $standard_days\n";
    
    #Business Days
    my $business_delta = DateCalc($start,$end,3);
    my $business_days  = Delta_Format($business_delta,2,'%dt');
    print "$business_delta :: $business_days\n";
    

    and the results were:

    +0:0:9:4:0:0:0 :: 67.00
    +0:0:0:47:0:0:0 :: 47.00
    

    Note that I changed the business day calc mode to 3 (which is an exact business delta). By treating both exactly, you get accurate numbers which you won't get with approximate deltas.

      That is informative! Thanks!
      ...the majority is always wrong, and always the last to know about it...
      Insanity: Doing the same thing over and over again and expecting different results.

      Your reply is greatly appreciated, tardy or not! I wish I knew the version I was using, however that information seems to have been lost. I wasn't event aware that there was a 3rd mode for exact business delta. That is exactly what I needed! Thanks, Nathan

        The version is available (in almost every single module you can get from CPAN) as $VERSION in the module's namespace. For example, the following will usually work:

        use Foo::Bar;
        print $Foo::Bar::VERSION;
        

        For Date::Manip, that will work, or there's an alternative:

        use Date::Manip;
        print DataManipVersion();
        

        which just prints out that value.