It doesn’t get parsed and just prints out the same ISO string that I’m trying to parse: 2/12/17 00:00:52
What could I be doing wrong? Thank you in advance and will be sure to vote up and accept the answer
This happens because the representation of a datetime variable (that is the result of dateutil.parser.parse, btw) is to print the ISO representation of the date.
However, if you store the variable instead of simply printing it after parsing it, you can print each individual part of the date:
date = dateutil.parser.parse("2017-02-16 22:11:05+00:00")
print(date.year)
2017
print(date.month)
2
print(date.day)
16
print(date.hour)
22
print(date.minute)
11
print(date.second)
5
Cheers!
What do you mean it didn't parse... it did but then you asked to print it back out again it turns it back into a string:
>>> import dateutil.parser
>>> date = dateutil.parser.parse("2017-02-16 22:11:05+00:00")
>>> repr(date)
'datetime.datetime(2017, 2, 16, 22, 11, 5, tzinfo=tzutc())'
>>> date.timetuple()
time.struct_time(tm_year=2017, tm_mon=2, tm_mday=16, tm_hour=22,
tm_min=11, tm_sec=5, tm_wday=3, tm_yday=47, tm_isdst=0)
>>> str(date)
2017-02-16 22:11:05+00:00