dotty
dotty

Reputation: 41433

Add 2 hours and 1 day onto a timestamp in django

i have a model which holds data for a game, how would i add 2 hours and 1 day onto the 'starts' field?

class Game(models.Model):
    starts = models.DateTimeField(auto_now_add=True)
    ends = models.DateTimeField()

does anyone have a solution for this?

Upvotes: 8

Views: 10991

Answers (1)

DrTyrsa
DrTyrsa

Reputation: 31951

from datetime import timedelta
obj.starts += timedelta(days=1, hours=2)

Upvotes: 21

Related Questions