Hello all!
I am parsing a csv file and one of the fields is a date time field that looks something like this
2010-01-15 23:15:30
year-month-day hour24:minute:s econd
as i loop through this csv i am going to need to do some time arithmetic. my question is, how do i turn that field from a string in my list to a datetime object?
lost and would greatly appreciate anyones help with this... Using Python 2.6.3
Thanks ahead of time.
Cheers,
Eric
I am parsing a csv file and one of the fields is a date time field that looks something like this
2010-01-15 23:15:30
year-month-day hour24:minute:s econd
as i loop through this csv i am going to need to do some time arithmetic. my question is, how do i turn that field from a string in my list to a datetime object?
Code:
from datatime import datetime
TmpArr = []
reader = open("c:/test.csv",'r')
for line in reader:
TmpArr = line.split(',')
#now TmpArr[1] contains the datatime data
#i've tried this
dt = datetime(TmpArr[1])
#but get a needs an integer error
#i've tried this too
dt = datetime.strtime(TmpArr[1],"%Y-%M-%D %h:%m:%s")
# then i get a needs datetime object
Thanks ahead of time.
Cheers,
Eric
Comment