A little help please


3 posts
by AshleyC » Mon Jun 25, 2012 6:48 pm
Hi all,

I have searched and read through the docs within python but still cant find the command i need and hoping someone will be able to help.

I have the following line in my program to grab the current date/time:

localtime = time.asctime( time.localtime(time.time()) )

Im trying to get function to execute when it reaches a time i set within the program, similar to an alarm clock really.

what command do i need to enter to match the time but ignore the day/month/year?

Im not lazy, i did try finding out and trying different things but i find i learn easier if im shown lol

Thanks
Posts: 26
Joined: Sat Jun 16, 2012 1:34 pm
Location: Derby
by andyl » Mon Jun 25, 2012 7:12 pm
AshleyC wrote:Hi all,

I have searched and read through the docs within python but still cant find the command i need and hoping someone will be able to help.

I have the following line in my program to grab the current date/time:

localtime = time.asctime( time.localtime(time.time()) )

Im trying to get function to execute when it reaches a time i set within the program, similar to an alarm clock really.

what command do i need to enter to match the time but ignore the day/month/year?

Im not lazy, i did try finding out and trying different things but i find i learn easier if im shown lol


I would use the DateTime module.

Code: Select all
from datetime import datetime

currentDateTime = datetime.now()

if currentDateTime.hour == 20 and currentDateTime.minute == 10:
   do_something()


Of course if it is a small program that I want to run in its entirety I would use cron to schedule it.
Posts: 265
Joined: Tue Jan 10, 2012 11:05 am
by AshleyC » Mon Jun 25, 2012 7:27 pm
That is just what i wanted, thanks for your help and time :)
Posts: 26
Joined: Sat Jun 16, 2012 1:34 pm
Location: Derby