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

In reply to execute if date is greater then 2hours by snehit.ar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.