0

I have an database called sportschool and one record looks like this

ID Logouttime Logintime totaltime

What i want to do is for example where id is 1(this can be different depending on the user input) is retreive the logintime and store that in a variable

This is what i have now:

aa= pymysql.connect(host='',user='',passwd='',db='',)
mm = aa.cursor()
mm.execute('SELECT Logouttime FROM sportschool WHERE ID = 1')

but how can i store it in a variable then? Insert works fine but i need to retreive the data and store it so i can calculate the difference betwheen logintime and loguittime

Hope someone can help

2 Answers 2

1

What you are looking for is the line

logouttime = mm.fetchone()

More info here: http://pymssql.org/en/stable/pymssql_examples.html

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the command i did what you said But when i print logguittime it prints it like this: {u'loguittime': datetime.timedelta(0, 58981)} in phpmyadmin it stands like this: 16:23:01
0
logouttime = mm.fetchone()

it will give you tuple of tuple

    (("10:00:00"))

now you can do whatever you want with that logout time

>>> import datetime
>>> a = {u'loguittime': datetime.timedelta(0, 58981)}
>>> a['loguittime']
     datetime.timedelta(0, 58981)
>>> d = a['loguittime']
>>> (d.days, d.seconds, d.microseconds)
    (0, 58981, 0) 

5 Comments

Thanks for the command i did what you said @BloodringBanger But when i print logguittime it prints it like this: {u'loguittime': datetime.timedelta(0, 58981)} in phpmyadmin it stands like this: 16:23:01
thats the problem with date time you need to parse it and then you can perform operations onto it
And by any change do you know how to do that?
This is something that is easily found by a google search I suppose. Try "parsing datetime python". Good luck!
@Klaas see this is how you will parse

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.