I've always found it easiest to deal with time/date stuff by first converting the dates I'm dealing with to seconds since the epoch. Which, conviently, is returned to us by the time function. Additionally, we can make use of the Time::Local module to convert dates to seconds. So, I might try something like this:
use strict;
use Time::Local;
# Time::Local uses an index of 0 for the month
# (as does localtime and gmtime)
# Lower Limit
my $year1 = 2001;
my $month1 = 7;
my $day1 = 6;
my $hour1 = 20;
my $min1 = 00;
my $sec1 = 00;
# Upper Limit
my $year2 = 2001;
my $month2 = 7;
my $day2 = 6;
my $hour2 = 20;
my $min2 = 59;
my $sec2 = 00;
# Convert the lower limit into seconds
my $min_time = timelocal($sec1,$min1,$hour1,$day1,$month1,$year1);
# Convert the upper limit into seconds
my $max_time = timelocal($sec2,$min2,$hour2,$day2,$month2,$year2);
# Get the current time, in seconds
my $now = time();
# If we haven't yet reached the minimum time
if ($now < $min_time) {
print "It's before my time!";
}
# If we're past due
elsif ($now > $max_time) {
print "It's after my time!";
}
# Otherwise, we're right on time!
else {
print "Ahhh, just right!";
}
Now, I'm not quite sure what you're using this for -- but do remember, if you just need tasks to be run every so often, you always have the NT "at" scheduler you can use to schedule jobs to run on a periodic basis.
-Eric
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.