mysql - Python/Raspberry pi 3: comparing strftime time to integer time in database -
my goal have simple if statement compares actual time displayed on raspberry pi (for example, 5pm reads 1700 on pi), integer user has defined , stored in database. (for example, user inputted military time reading of 5pm in military time 1700, once submitted, integer value 1700 gets stored in database.
if users inputted time equal actual time, want print hello world or of sort.
i think problem having database integer not retuning value can compared strftime("%h%m") command... suggestions?
when print value of userin_time1 (variable assigned retrieve newest value in database, 2018), return value is:
(2018l,)
the command use actual time on pi strftime("%h%m") returns value:
2018
i thinking maybe parenthesis , l , comma messing logic edited strftime function this:
strftime("(%h%ml,)")
in doing this, code compiles , returns value:
(2018l,)
when assign both pi's time (strftime function) , users inputted time (userin_time1 function) new variable x , y respectively, , compare them using statement:
if(x==y): print 'hello world'
the code runs when condition met (the times line each other perfectly) nothing happens...
you can try this,
from datetime import datetime time import gmtime, strftime d = datetime.strptime("2018", "%h%m") db_time = d.strftime("%i:%m%p") #results '08:18pm' current_time = strftime("%i:%m:%p", gmtime()) if db_time == current_time: print "time matched" else: print "time not matched" is expecting?
Comments
Post a Comment