-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatetimechange.py
More file actions
24 lines (20 loc) · 855 Bytes
/
datetimechange.py
File metadata and controls
24 lines (20 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import datetime
import csv
pathtofile='C:\\users\\jeremiah.marks\\Desktop\\calls (3).csv'
pathtofileout='C:\\users\\jeremiah.marks\\Desktop\\callsThree.csv'
formatin = '%d/%m/%Y %H:%M'
formatout = '%m/%d/%Y %H:%M'
fuckedFields=[ "Start Date and Time","Date End"]
with open(pathtofile, 'rb') as currentfile:
rdr=csv.DictReader(currentfile)
with open(pathtofileout, 'wb') as outfile:
wtr = csv.DictWriter(outfile, rdr.fieldnames)
wtr.writeheader()
for eachrow in rdr:
thisrow={}
for eachcolname in eachrow:
if eachcolname in fuckedFields:
thisrow[eachcolname] = datetime.datetime.strptime(eachrow[eachcolname], formatin).strftime(formatout)
else:
thisrow[eachcolname] = eachrow[eachcolname]
wtr.writerow(thisrow)