0

Want to add some time to existing date.

>>date='2013-11-16  22:00:00'
>>newdate = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S').date()
>>print newdate
>>datetime.date(2013, 11, 16)

The last line is showing only date but not time. Why there is no time in last line ? How can i get date with added some time ?

Nishant Nawarkhede
  • 8,234
  • 12
  • 59
  • 81
  • 1
    `date()` converts a `datetime` object into a `date` object, which does not have a time. Why are you using it if you want the time? If you want to create a `datetime` object for a fixed time on the variable `date` object, `datetime.datetime.combine` is the preferred way to do that. – Peter DeGlopper Dec 24 '13 at 06:17
  • 1
    I think the followin link could help you guy: http://stackoverflow.com/questions/100210/python-easy-way-to-add-n-seconds-to-a-datetime-time – MLSC Dec 24 '13 at 06:18
  • 1
    Come to think of it, if you're starting from a string representing a datetime and want to change the time without changing the date, the `replace` method on the results of `datetime.datetime.strptime` might be the best way. – Peter DeGlopper Dec 24 '13 at 06:23

0 Answers0