Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Substract 15 Minutes from time using Perl

Tags:

datetime

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.

Example 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.

like image 437
The Man Avatar asked Jul 13 '11 11:07

The Man


1 Answers

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
like image 87
Eugene Yarmash Avatar answered Oct 21 '22 11:10

Eugene Yarmash