如何减去这两个日期?如何计算它们之间的分钟数?

时间:2013-07-08 10:53:03

标签: python django datetime python-datetime

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

如何在when_startwhen_end之间获得分钟差异?

my_minutes = when_end - when_start = #number of minutes

2 个答案:

答案 0 :(得分:2)

我愿意

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

答案 1 :(得分:2)

当你减去时,你会得到这样的东西:

datetime.timedelta(0, 5, 41038)

将其转换为分钟:

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