#!/usr/bin/env python #encoding: utf-8 import datetime def dateDiffInHours(t1, t2): td = t2 - t1 return td.days * 24 + td.seconds/3600 + 1 if __name__ == '__main__': t1 = datetime.datetime(2016, 3, 31, 0) t2 = datetime.datetime(2016, 6, 8, 2) print dateDiffInHours(t1, t2)