This question already has an answer here:
I am trying to take a variable (String), convert it to a DateTime object to increment the day and then convert back to a string again.
The reason for this converting is that the string variables I'm starting with are being read from an SQLite database table. As far as I'm aware SQLite does not support DateTime?
See below for example.
Original String Format:
temp_data = 'May 28 2015'
I then convert it to a dateTime obeject:
temp_data = datetime.datetime.strptime(temp_date, '%d %b %Y')
Then increment the date by one day:
temp_data += datetime.timedelta(days=1)
Which results in temp_data having the following value:
2015-05-29 00:00:00
However, I now want to convert my new temp_data variable back to a string in the format:
'May 29 2015'
I thought I could make use of the strftime function but not completely sure. Would appreciate any help I could get with this.
Thanks.
Aucun commentaire:
Enregistrer un commentaire