0

I am currently working on a code where I want to implement something like this:

if current_time is more that 12_am:
     hello = "world"

Basically I want to set or change a variable if the current time in my computer is more than 12 am.

I did some research on datetime, however I could not find a function that does as told above.

If there is already an answer to this, please do redirect me and excuse my clumsiness.

bastelflp
  • 9,362
  • 7
  • 32
  • 67
  • Possible duplicate of [Postponing functions in python](http://stackoverflow.com/questions/5177439/postponing-functions-in-python) – jfs Jan 10 '16 at 16:02
  • Is there any reason not to use crontab or Windows task manager to schedule the script? – jfs Jan 10 '16 at 16:03
  • What are you actually trying to do? If the current time is not exactly 12 am, it it always past (greater than) the last 12 am and before (less than) the next 12 am. With a 24 hour clock, 12 am is `00:00:00` and all other clock times are greater than that, up to `23:59:59`. – Terry Jan Reedy Jan 11 '16 at 00:50
  • To be more specific, i am making a movie theater program, where if the current time is greater than 12 am midnight, i want to charge higher prices for the movies. – Swag Meister Jan 11 '16 at 03:14

2 Answers2

-1

You need to constantly run your script and check whether date is more than 12 am.

Another aproach would be to check how much time left and sleep for that long.

bercik
  • 816
  • 1
  • 9
  • 18
-1

The script needs to be running consantly. You can set the check to True and then maybe break the while loop. All depeneds on your application.

import time

while True:
    if int(time.strftime("%H")) > 12:
        check = True

Let's say you are writing a program for Raspberry and you control some lights and you turn them on only after a certain time. On microcontrollers the programs always run endlessly.

Jozef Méry
  • 357
  • 5
  • 15