now = date.today() set_date=datetimeObj.date() set_date2=datetimeObj2.date() code example
Example 1: strptime python
import datetime
d =datetime.datetime.strptime("01/27/2012","%m/%d/%Y").strftime('%m/%d/%Y')
print d
01/27/2012
Example 2: python datetime to string iso format
from datetime import datetime
some_date = datetime.now()
iso_date_string = some_date.isoformat()
# For older version of python
iso_date_string = some_date.strftime('%Y-%m-%dT%H:%M:%S.%f%z')