views:

397

answers:

3

I would like to know many minutes between 2 dates?

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

+4  A: 

Look at the TimeSpan class.

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

        TimeSpan diff = date2.Subtract(date1);
        Console.WriteLine(diff.Minutes);
FlySwat
Vendetta downvoting is funny.
FlySwat
If it weren't for your rep, I'd say "Welcome to SO!" ;)
rcreswick
Lol...Hi to another Seattilite
FlySwat
Console.WriteLine(diff.Minutes); should be Console.WriteLine(diff.TotalMinutes) ;)
Daok
Really? Try both.
FlySwat
A: 
DateTime currentTime = DateTime.Now;
DateTime tommorowTime = currentTime.AddDays(1);
TimeSpan diffTime = tommorowTime - currentTime ;
Console.WriteLine(diffTime.TotalMinutes);
Daok
+4  A: 
DateTime dt1 = DateTime.Now;
DateTime dt2 = DateTime.Now.AddDays(1);

int diff = dt2.Subtract(dt1).TotalMinutes;
John Sheehan
He said tommorow, not yesterday :)
FlySwat
Vote reversed :)
FlySwat