Python script to convert date to iso format

Hi ,

This is my 1st program in python never tried any python before.

i am trying to write a python script which reads a .tsv file line by line and in each line it should look for mm/dd/yyyy formate and convert it to yyyy-mm-dd formate . can some one provide be some sample code to do that.

from time import strptime, strftime

date_in = '10/16/2013'

date_out = strftime('%Y-%m-%d', strptime(date_in, '%m/%d/%Y'))

print date_out

Emanuele

Try something like this:

#!/usr/bin/env python
from time import strptime, strftime
import re
import sys

while 1 :
        line = sys.stdin.readline().strip()
        if not line : break
        while 1 :
            match = re.match(".*(\d{2}/\d{2}/\d{4}).*", line)
            if not match : break
            line = line.replace(match.groups()[0], strftime('%Y-%m-%d', strptime(match.groups()[0], '%m/%d/%Y')))
        print line