Datetime strptime in python

You need to make sure you provide input accordingly

datetime.strptime(date_string,date_string_format).strftime(convert_to_date_string_format)

To print the date in specified format you need to provide format as below.

import datetime
d =datetime.datetime.strptime("01/27/2012","%m/%d/%Y").strftime('%m/%d/%Y')
print d

Output:

01/27/2012

>>Demo<<

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)