Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Python, how do I make a datetime that is 15 minutes from now? 1 hour from now? [duplicate]

Possible Duplicates:
Python - easy way to add N seconds to a datetime.time?
How to create a DateTime equal to 15 minutes ago?

what's the best way to do this?

like image 235
TIMEX Avatar asked Dec 29 '10 20:12

TIMEX


People also ask

How do you add minutes to a datetime?

Use the timedelta() class from the datetime module to add minutes to datetime, e.g. result = dt + timedelta(minutes=10) . The timedelta class can be passed a minutes argument and adds the specified number of minutes to the datetime.


1 Answers

d1 = datetime.datetime.now() + datetime.timedelta(minutes=15)
d2 = datetime.datetime.now() + datetime.timedelta(hours=1)
like image 108
nosklo Avatar answered Oct 10 '22 23:10

nosklo