How Do I Parse Dates With More Than 24 Hours In Dateutil's Parser In Python 3?
I currently have a bunch of times in a column written like '27:32:18', meaning someone was waiting for 27 hours, 32 minutes, and 18 seconds. I keep getting 'ValueError: hour must
Solution 1:
You don't have a date, you have a time duration. That may be related to dates and timestamps, but only in that the same units of time are involved and are displayed similarly to timestamps.
As such, you cannot use dateutil
for parsing such values. It is easy enough to split out and parse yourself:
hours, minutes, seconds = map(int, time1.split(':'))
You can then use a datetime.timedelta()
object to represent the duration:
td = datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)
This'll then track the delta in terms of days, seconds and microseconds:
>>>import datetime>>>time1 = "56:42:12">>>hours, minutes, seconds = map(int, time1.split(':'))>>>datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds)
datetime.timedelta(2, 31332)
Post a Comment for "How Do I Parse Dates With More Than 24 Hours In Dateutil's Parser In Python 3?"