http://www.perlmonks.org?node_id=94685


in reply to Within A Date Time Range

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