Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact time between 2 DateTime?

I would like to know many minutes between 2 dates?

Example : Now - tommorow at the exact time would return me 1440.

like image 429
Mister Dev Avatar asked Oct 16 '08 23:10

Mister Dev


2 Answers

DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now.AddDays(1);

int diff = dt2.Subtract(dt1).TotalMinutes;
like image 189
John Sheehan Avatar answered Sep 21 '22 13:09

John Sheehan


Look at the TimeSpan class.

        DateTime date1 = DateTime.Now;
        DateTime date2 = DateTime.Now.AddDays(1);

        TimeSpan diff = date2.Subtract(date1);
        Console.WriteLine(diff.Minutes);
like image 31
FlySwat Avatar answered Sep 20 '22 13:09

FlySwat