How to calculate days, ignoring hours

3

How can I calculate if you spent 1 day, ignoring the hours. Explaining, it would look something like this:

I have a date 2017-09-09 11:45:20 , normally it would have been 1 day, when the 11:45 arrived the other day, however I would like it to count as 1 day as soon as it gives 00:00:00 .

Even though I have the following date 2017-09-09 23:59:59 and now it was 2017-09-10 00:00:00 . I literally just went 1 minute , but I want it to count as 1 day .

  

I tried to do this, but it returned me 0:

//                          mês/dia/ano hora:min:seg
// questData.CompletedDate   09/09/2017 11:45:20
// DateTime.Today            09/10/2017 00:00:00
int totalDays = (int)DateTime.Today.Subtract(questData.CompletedDate).TotalDays;

How could I do this in C #?

    
asked by anonymous 10.09.2017 / 18:21

1 answer

5

Just pick up the days part with the property Date of DateTime .

using System;
using static System.Console;

public class Program {
    public static void Main() => WriteLine((new DateTime(2017, 09, 10, 11, 45, 00).Date - new DateTime(2017, 09, 09, 11, 45, 20).Date).TotalDays);
}

See running on .NET Fiddle . And no Coding Ground . Also put it in GitHub for future reference .

    
10.09.2017 / 18:33