Skip to content

Instantly share code, notes, and snippets.

@kovshenin
Created July 17, 2012 04:51
Show Gist options
  • Save kovshenin/3127242 to your computer and use it in GitHub Desktop.
Save kovshenin/3127242 to your computer and use it in GitHub Desktop.
Rewrite m/d/y dates to Y-m-d in a PayPal CSV export
"""
This script will rewrite the date column in a PayPal CSV
export from m/d/y to Y-m-d format.
Usage:
# python fix-paypal-csv-dates.py input_file.csv > output_file.csv
"""
import csv, sys
from time import strptime, strftime
filename = sys.argv[1]
try:
reader = csv.reader(open(filename, 'rb'), delimiter=',', quotechar='"')
writer = csv.writer(sys.stdout, delimiter=',', quotechar='"')
except IOError as e:
print e
exit()
for row in reader:
try:
t = strptime(row[0], "%m/%d/%Y")
row[0] = strftime("%Y-%m-%d", t)
except ValueError:
pass
writer.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment