Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Within A Date Time Range by andreychek
in thread Within A Date Time Range by mumbles

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found