You need the strptime method. If you use Python 2.5 or higher, this is a datetime method, otherwise you must use a combination of time and datetime modules for this.
Python 2.5 up:
from datetime import datetime dt = datetime.strptime(s, "%d/%m/%Y-%H:%M:%S")
below 2.5:
from datetime import datetime from time import strptime dt = datetime(*strptime(s, "%d/%m/%Y-%H:%M:%S")[0:6])
source share