I'm trying to parse a datetime field using python (but have never used python for it before). I have a field that contains a valid date, but not a valid time... and other fields that have valid hour and am/pm information. I need to grab the date (mm/dd/yy) from the datetime field and then combine that with the valid hour and am/pm fields into a new string field.
Below is the vbscript way that I would do this (and it works fine, but I need to build it using python):
(DatePart ( "m", [STARTDATE])) &"/"&
(DatePart ("d", [STARTDATE] )) &"/"&
(DatePart ("yyyy", [STARTDATE] )) &" until "&
(DatePart ( "m", [ENDDATE])) &"/"&
(DatePart ("d", [ENDDATE] )) &"/"&
(DatePart ("yyyy", [ENDDATE] )) &" (from "&
[StartHour] &" "&
[StartAMPM] &" until "&
[EndHour] &" "&
[EndAMPM]&" )"
Here's what I've written so far using python (but doesn't work):
def dateFull(oid)
startDateObj = datetime.datetime.strptime( !STARTDATE! , "%m/%d/%Y")
endDateObj = datetime.datetime.strptime( !ENDDATE! , "%m/%d/%Y")
return startDateObj + " to " + endDateObj + " from " + !StartHour! + " " + !StartAMPM! + " to " + !EndHour! + " " + !EndAMPM!
Can someone please help me figure out what I'm doing wrong here?