What is the best way to check if time is within a certain minute?
<p>I want to write a simple python script which will check to see if it's 2 minutes before a given hour/minute, and then call my function either everyday or for a given date at the given time.</p>

<p>The script will run every minute in a cronjob.</p>

<p>So the two cases to execute myfunction():</p>

<p>10:55 everyday<br/>
10:55 on 9/28/2012</p>

<p>But I am having trouble determining when it's 2 minutes prior to the given hour/minute using datetime. Also, how to determine everyday vs just on a given day?</p>

<pre><code>mydate = datetime(2012, 09,28, 10,55)
check = mydate - datetime.now()    # gives you a timedelta

if check &lt; datetime.timedelta(minutes=2):
     run_myfunction()
</code></pre>

<p>The above sees if it's within 2 minutes, and if it is, then runs the myfunction(). The problem with the above code is that if the mydate has passed, the myfunction() will still run. Also, this requires that a specific date to be specified. How would one allow the check for everyday rather than 9/28/2012?</p>
