Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Hello,

    You might want to consider something along these lines.

    use strict;
    use warnings;
    use DateTime;
    use DateTime::Format::Duration;
    use Data::Dumper;

    my $dt1 = DateTime->now(
              time_zone => 'UTC',
             );

    my $dt2 = DateTime->new(
            year  => 2006,
            month => 10,
            day => 31,
            time_zone =>'UTC',
        );

    my $delta = $dt1->delta_ms($dt2);

    print Dumper($delta), "\n";
    my $d = DateTime::Format::Duration->new(
            pattern => '%M minutes'
    );
    print $d->format_duration($delta);

    Here I used the delta_ms method (see the docs) to create the duration. Also don't forget to use the format_duration method for getting at the value of minutes :-)

    I hope this helps.