Reputation: 25
I know there's a pre-function differences
for DateTime to calculate the duration differences between two DateTime. But I need to calculate the date differences between two DateTime
. For example, the differences between 2020-03-01 23:59:59
and 2020-03-02 00:00:01
should return 1. How can I do that? Thanks in advances
Upvotes: 0
Views: 65
Reputation: 54
If you create another two DateTime objects using only the year , month and day of the months of the previous dates using the 'DateTime' constructor it should work. Like so :
DateTime date1,date2;//These should be initialized
Duration difference = DateTime(date1.year,date1.month,date1.day).diffrence (DateTime(date2.year,date2.month,date2.day));
print (diffrence.inDays);
Upvotes: 2