0

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.

p_cos
  • 185
  • 1
  • 9
  • what error did you get from strftime? your code? – Skaperen May 28 '15 at 10:33
  • @Skaperen When I use 'temp_date = strftime(temp_data, '%d %b %Y')' I get a TypeError: must be string, not datetime.datetime as my temp_data is not a string format. If I convert it to a string before performing, I get the error: TypeError: argument must be 9-item sequence, not str – p_cos May 28 '15 at 10:36
  • "However, I now want to convert my new temp_data variable back to a *string* in the format:" ... this is where to use `datetime.strftime()`. – Skaperen May 28 '15 at 11:57

0 Answers0