95

I want to find out the datetime 10 mins after current time. Let's say we have

from datetime import datetime  
now = datetime.now()  
new_now = datetime.strptime(now, '%a, %d %b %Y %H:%M:%S %Z')  

I want to find this now and new_now 10 minutes later. How can I do that?

ivanleoncz
  • 9,070
  • 7
  • 57
  • 49
sam
  • 18,509
  • 24
  • 83
  • 116

3 Answers3

186

This is a duplicate of this question. You basically just need to add a timedelta of 10 minutes to get the time you want.

from datetime import datetime, timedelta
now = datetime.now()
now_plus_10 = now + timedelta(minutes = 10)
JDOaktown
  • 4,262
  • 7
  • 37
  • 52
efalconer
  • 2,551
  • 1
  • 17
  • 10
  • 1
    while using with strftime('%a, %d %b %Y %H:%M:%S %Z'), if i want to use GMT as well how can I do that as I am not able to get GMT using this – sam Jun 02 '11 at 04:55
  • 1
    If you want to get the GMT, then you use utcnow() instead of now() and then add the timedelta to that in order to get the UTC time 10 minutes from now. UTC is just a different name for GMT. – efalconer Jun 02 '11 at 17:23
  • 1
    One thing that could be nice to add, is that you can obtain a more "human" date/time format, using `str()`, like this: `>>> str(datetime.datetime.now()) ---> '2017-10-11 13:43:21.671497'`, if you need to store the date into a database or for any other purpose. – ivanleoncz Oct 11 '17 at 18:43
  • Note that `datetime` does not support leap seconds. https://bugs.python.org/issue23574 – Eero Aaltonen Mar 19 '18 at 14:47
13
now_plus_10m = now + datetime.timedelta(minutes = 10)

See arguments you can pass in the docs for timedelta.

istruble
  • 13,363
  • 2
  • 47
  • 52
Akash
  • 277
  • 2
  • 11
11

I'd add 600 to time.time()

>>> import time
>>> print time.ctime()
Wed Jun  1 13:49:09 2011
>>> future = time.time() + 600
>>> print time.ctime(future)
Wed Jun  1 13:59:15 2011
>>> 
tMC
  • 18,105
  • 14
  • 62
  • 98