Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Within A Date Time Range

by andreychek (Parson)
on Jul 07, 2001 at 07:55 UTC ( #94685=note: print w/ replies, xml ) Need Help??

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.
Comment on Re: Within A Date Time Range
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://94685]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-05-26 02:50 GMT
Find Nodes?
    Voting Booth?