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

I've been having trouble working out how to use the format specifiers for Date:::Manip::Delta_Format().

If I have a delta as returned from DateCalc() in the same module that looks like +0:0:14:6:23:51:0 representing a period of 14 weeks, 6 days, 23hrs and 51 minutes, and I would like to use Delta_Format() to present this as 104 days 23.85 hrs

I thought that a format of '%dh %hd' would achieve this, but was wrong. Can anyone enlighten me?


Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!

Replies are listed 'Best First'.
Re: Date::Manip::Delta_Format() format specifiers
by Enlil (Parson) on Sep 17, 2002 at 18:18 UTC
    This seemed to work:
    $delta='0:0:14:6:23:51:0'; $dec=2; @format=('%dh','%hd' ); use Date::Manip; @str=&Delta_Format($delta,$dec,@format); print "$str[0] days $str[1] hours\n";

      Thankyou Enlil. I was completely mis-interpreting the pod on how to supply the format. It could definately do with a few more examples, but I find that a lot.

      Thanks again.


      Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
Re: Date::Manip::Delta_Format() format specifiers
by jsprat (Curate) on Sep 17, 2002 at 18:19 UTC
    Looks like it does work, if this is what you expected:

    #!/usr/bin/perl use strict; use warnings; use Date::Manip; $ENV{TZ} = 'PDT'; my $date1 = ParseDate('January 1, 2001 10:06AM'); my $date2 = ParseDate('January 31, 2002 10:00PM'); my $delta = DateCalc($date1, $date2); #, \$err); print "\$delta = $delta\n"; # Here's the $format my $format = '%dh days %hd hours'; $delta = Delta_Format($delta, 2, $format); print "\$delta (formatted) = $delta\n";

    Output:

    C:\S\Test>dm.pl $delta = +0:0:56:3:11:54:0 $delta (formatted) = 395 days 11.90 hours