My guess is that you also have a date field in the database for the record time. If you do, then I would convert the date/time to unixtime and then do the comparison:

use HTTP::Date; my $start_time = str2time('2005-10-01 22:00:00'); my $end_time = str2time('2005-10-02 04:00:00'); my $check_time = str2time('2005-10-01 22:40:00'); if ($start_time < $end_time) { if ($start_time < $check_time and $check_time < $end_time) { print "yes\n"; } else { print "no\n"; } } elsif ($end_time < $start_time) { if ($end_time < $check_time and $check_time < $start_time) { print "yes\n"; } else { print "no\n"; } } else { print "Start and End times are identical\n"; }

For the sake of clarity, I left out retrieving the db times and left them as strings. Also, as others have pointed out, this is easily doable in the db with a simple SQL query:

SELECT 1 WHERE check_time BETWEEN start_time AND end_time or SELECT 1 WHERE concat(check_date, ' ', check_time) BETWEEN concat(star +t_date, ' ', start_time) AND concat(end_date, ' ', end_time)
</code>

In reply to Re: Check Time between 2 other times by hubb0r
in thread Check Time between 2 other times by dtharby

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.