Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to set up some code that depending on the time of day (internal computer time i guess). It switches to do something else.

Heres in english:

y = 1 <br>
if 6:30am then<br>
  x = 1 + y<br>
if 7:00am then<br>
  x = 2 + y<br>
if any_other_time then<br>
  x = 0<br>

Here is what i have so far in my script.

import time<br>
clock = time.time()
y = 0
if clock < 6:30am
x = 2 + y

but i know this isn't right because time.time displays something different then 6:30am

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

IMHO i would use the datetime library

http://docs.python.org/library/datetime.html

eg.

>>> datetime.utcnow()   
datetime.datetime(2007, 12, 6, 15, 29, 43, 79060)

check this post too

http://stackoverflow.com/questions/1599060/how-can-i-get-an-accurate-utc-time-with-python

share|improve this answer
    
how is this looking: pastebin.com/uD7xr0bh –  John Riselvato Nov 17 '10 at 18:57
    
Ohh run ntpclients on your servers too... :D –  Arenstar Nov 17 '10 at 18:59
    
haha yeah i do. Trying to set up a bandwidth controller. So that at certain times, it shapes differenly. –  John Riselvato Nov 17 '10 at 19:00
    
Are you focusing on a single server, or wanting to run it for the network? BTW, looks very interesting :D –  Arenstar Nov 17 '10 at 19:02
    
More of a learning experience. I don't need it, but i am trying to teach my self Lartc. So i figured make up tasks a 'boss' would ask. So atleast when i do have a task like this i can already do it, or atleast have reference. –  John Riselvato Nov 22 '10 at 18:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.