I was wondering if anyone could help me refactor the following Python code:
In this example, endDate is a string like such: "2012-08-22"
dateArray = [int(x) for x in endDate.split('-')]
event.add('dtend', datetime(dateArray[0], dateArray[1], dateArray[2]))
I appreciate it!
from datetime import strptime
event.add('dtend', strptime(endDate, '%Y-%m-%d')
Better use datetime.strptime:
>>> from datetime import datetime
>>> strs = "2012-08-22"
>>> datetime.strptime(strs,'%Y-%m-%d')
datetime.datetime(2012, 8, 22, 0, 0)
For your code:
event.add('dtend', datetime.strptime(endDate,'%Y-%m-%d'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With