user323212
user323212

Reputation: 27

How to subtract these two dates? How to count the number of minutes between them?

when_start = models.DateTimeField()
when_end = models.DateTimeField()

How can I get the difference in minutes between when_start and when_end?

my_minutes = when_end - when_start = #number of minutes

Upvotes: 1

Views: 97

Answers (2)

lakshmen
lakshmen

Reputation: 29064

When you subtract, you are going to get something like this:

datetime.timedelta(0, 5, 41038)

To convert it to minutes:

minutes = (when_end - when_start).total_seconds()/60

Upvotes: 2

log0
log0

Reputation: 10917

I would do

my_minutes = (when_end - when_start).total_seconds() / 60

Upvotes: 2

Related Questions