Well, I have datetime objects with information like 2013-10-01 14:15:00 and time objects like
- 1900-01-01 00:00:49.235000
- 1900-01-01 00:00:49.465000
- 1900-01-01 00:00:49.695000
The time objects are actually progressive increments which I'd like to add to the datetime object. As described here,
If date is a datetime object, its time components and tzinfo attributes are ignored.
I wrote the code below. How should it be updated to be able to add these time objects to the datetime object as increments?
def CombineDateTime(date_str, time_str, date_fmt, time_fmt, equipment, sample_name):
import datetime
try:
date_obj = datetime.datetime.strptime(date_str, date_fmt)
time_obj = datetime.datetime.strptime(time_str, time_fmt)
return datetime.datetime.combine(date_obj.date(), time_obj.time())
except:
return 'Error'
Output:
- 2013-10-01 00:00:49.235000
- 2013-10-01 00:00:49.465000
- 2013-10-01 00:00:49.695000
Expected output:
- 2013-10-01 14:15:49.235000
- 2013-10-01 14:15:49.465000
- 2013-10-01 14:15:49.695000