Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 0 down vote accepted

IMHO i would use the datetime library


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

check this post too

share|improve this answer
how is this looking: – 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

Your Answer


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.