Python Forum
convert date input to seconds - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: convert date input to seconds (/thread-2314.html)



convert date input to seconds - student001 - Mar-07-2017

Hi all, I am a beginner to python.
 
I am wondering on how to read input from user: 
DAY 3, 09:00 PM
and convert it to seconds?


RE: convert date input to seconds - ichabod801 - Mar-07-2017

In that specific format, or in a more standard datetime format (like '2/25/70 10:14pm')? If that specific format, the re module (with int() and some multiplication) would probably be best. Otherwise I would look at the time module.

In either case, try something, and when (if) it doesn't work we will help you fix it.


RE: convert date input to seconds - nilamo - Mar-24-2017

The time module is pretty rad:

>>> import time
>>> parsed = time.strptime("DAY 3, 09:00 PM", "DAY %d, %I:%M %p")
>>> parsed
time.struct_time(tm_year=1900, tm_mon=1, tm_mday=3, tm_hour=21, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=3, tm_isdst=-1)