How to get the number of days, hours and minutes elapsed from a date? in C #

1

I have tried to get the days, hours and minutes of a date from this:

DateTime fecha_actual= "26-07-2017 18:45";
DateTime fecha_ingreso= "25-07-2017 16:45";
TimeSpan ts = fecha_actual - fecha_ingreso
int differenceInDias = ts.Days;
int differenceInHours = ts.Hours;
int differenceInMinuntos = ts.Minutes;

The idea that you get the hours that have elapsed (26 hours) from 4 pm on the 25th, to the time of the current date, the same in minutes and hours.

    
asked by Danilo 27.07.2017 в 00:42
source

1 answer

2

Use TotalHours to get you gives the total hours of TimeSpan :

DateTime fecha_actual= new DateTime(day:26, month: 7, year: 2017, hour:18, minute:45, second: 0);
        DateTime fecha_ingreso= new DateTime(day:25, month: 7, year: 2017, hour:16, minute:45, second: 0);
        TimeSpan ts = fecha_actual - fecha_ingreso;

        var differenceInDias = ts.TotalDays;
        var differenceInHours = ts.TotalHours;
        var differenceInMinuntos = ts.TotalMinutes;
        Console.WriteLine(differenceInHours); // 26

Example in .Net Fiddle

    
answered by 27.07.2017 / 00:50
source