Want to compare 2 date and if hour is more then 2 hours then its should enter if condition and perform the action .
#!/usr/bin/perl
use warnings;
use strict;
use DateTime;
use DateTime::Duration;
# my $file = 'C:/Users/snehit.rahate/Perl/events.xml';
# #my $xpath = q{//custom_attribute_list/custom_attribute[normalize-sp
+ace(name)='SLB_SSRID']/value};
# my $xp = XML::XPath->new(filename=>$file);
# my $nodeset = $xp->find("//custom_attribute_list/custom_attribute[no
+rmalize-space(name)='SLB_SSRID']/value");
# for my $node ($nodeset->get_nodelist) {
# print " XML::XPath: ",$node->string_value,"\n";
# }
use DateTime::Format::Duration;
my $dtnow = DateTime->now;
$dtnow =~ s/T/ /;
$dtnow =~ m/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/gi;
my $now_hour = $4;
my $now_minute = $5;
my $now_second = $6;
my $dtevent = '2017-06-15 13:14:31';
$dtevent =~ m/(\d+)-(\d+)-(\d+)\s(\d+):(\d+):(\d+)/gi;
my $event_hour = $4;
my $event_minute = $5;
my $event_second = $6;
my $diffhour = $now_hour - $event_hour;
my $diffminute = $now_minute - $event_minute;
my $diffsecond = $now_second - $event_second;
my $event_time = $diffhour.":".$diffminute.":".$diffsecond;
print $event_time;
if ($event_time > "2:00:00") {
print "Start the service if time is more then 2 hours";
}
Error :Argument "2:00:00" isn't numeric in numeric gt (>) at test.pl line 37.
Argument "-6:-8:15" isn't numeric in numeric gt (>) at test.pl line 37.
-6:-8:15