Finding time difference between 2 times | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Finding time difference between 2 times

can any help me, I want to introduce minutes also in this code

1st Jun 2017, 9:18 PM
Ranvir
8 Answers
0
I cant see any codes but, if u want date and time in your code use: import datetime
1st Jun 2017, 9:30 PM
Noname Nonamer
Noname Nonamer - avatar
0
I'm sorry but my teacher said do without date time library
1st Jun 2017, 9:31 PM
Ranvir
0
You could transform the times into seconds (How many seconds have gone by since midnight?). Calculate the difference of the two and then transform them back. For more help you should provide the time-format.
1st Jun 2017, 11:09 PM
calp
0
As it is your homework, try on your own first, then post a code (I mean create a code in the playground and link it) and ask for help if you're stuck with something. It is your task for a reason :)
2nd Jun 2017, 5:25 AM
Lana
Lana - avatar
0
yeah I made a code but I don't know how to insert it here ...lol
2nd Jun 2017, 6:04 AM
Ranvir
0
@ranvir okay then, do you know where playground is? Open the tab and click green button with a plus to add your code and make it public. Then you can add a post and insert your code in here ("Insert" button on the left to the "Post") If you wrote your code on desktop you might want to use SoloLearn desktop version
2nd Jun 2017, 9:17 AM
Lana
Lana - avatar
0
I have posted it in my profile. Can somebody test it. Thank you
2nd Jun 2017, 10:25 PM
Ranvir
0
Your code works fine as far as I can see, but oh boy, how much easier your life would be with 24-hour format. I suggest you using function, maybe something like this def converter(str): hour = int(str[:str.find(":")]) if str.find("p"): hour +=12 minutes = int(str[str.find(":")+1:str.find("p")-1]) else: minutes = int(str[str.find(":")+1:str.find("a")-1]) t = [hour, minutes] return t With it you'll obtain 24-hour equivalent of the user input. Then you just pass your string to function and assign resulting values to respective variables. I hope the use of functions is not restricted. That way you won't need as many nested if statements, though the logic stays the same
3rd Jun 2017, 7:20 AM
Lana
Lana - avatar