Python Forum
convert date input to seconds
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert date input to seconds
#1
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?
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare current date on calendar with date format file name Fioravanti 1 116 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Python date format changes to date & time 1418 4 514 Jan-20-2024, 04:45 AM
Last Post: 1418
  Review my code: convert a HTTP date header to a datetime object stevendaprano 1 1,904 Dec-17-2022, 12:24 AM
Last Post: snippsat
  Problem with module time and leap seconds Pedroski55 3 1,189 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  Convert Date to another format lonesoac0 2 1,631 Mar-17-2022, 11:26 AM
Last Post: DeaD_EyE
  Store variable data and display sum after 60 seconds the_dude 11 3,366 Dec-16-2021, 07:07 PM
Last Post: deanhystad
  Date format and past date check function Turtle 5 4,066 Oct-22-2021, 09:45 PM
Last Post: deanhystad
  How to add previous date infront of every unique customer id's invoice date ur_enegmatic 1 2,190 Feb-06-2021, 10:48 PM
Last Post: eddywinch82
  Convert date integers (ex. 43831) to regular format Galven 2 2,552 Nov-15-2020, 11:38 PM
Last Post: bowlofred
  How to add date and years(integer) to get a date NG0824 4 2,802 Sep-03-2020, 02:25 PM
Last Post: NG0824

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020