The Man The Man - 2 years ago 95
Perl Question

Substract 15 Minutes from time using Perl

I thought this was going to be very simple but I am really out of options now. I want to substract 15 minutes from a given time.

My time is 15:04 I want to substract 15 minutes to be 14:49. I have searched for solutions on the internet but there is no perl module that can help me out.

Answer Source

You can use DateTime:

my $dt = DateTime->new(
    year   => 1,
    month  => 1,
    day    => 1,
    hour   => 15, 
    minute => 4,

$dt->subtract(minutes => 15);
printf "%d:%d\n", $dt->hour, $dt->minute; # prints 14:49
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download