Find and adjust the date and time stamp in XML using Python


I'm trying to change all date values in an XML and subsequently add or subtract an user specified amount of time from the time stamps.

The timestamps are all of the format 2016-06-29T17:03:39.000Z However, they are not all enclosed in the same tags

My XML looks something like this:

<Lap StartTime="2016-06-29T17:03:37.000Z">

I want to run through the XML file row by row, and search for the date/time string, then first find and replace the date, secondly add/subtract some amount of time from the timestamp.

This is my code so far:

import re
import xml.etree.ElementTree as et

name_file = 'test.txt'
fh = open(name_file, "r")
filedata =

filedata = filedata.split()
for line  in filedata:
    cur_date = re.findall('\d{4}[-/]\d{2}[-/]\d{2}', line)
    print cur_date

Does anyone have an idea on how to do this?

You can use this:


And then you can access the named groups like this:'YEAR')

P.S. You can see live demo here: