Diff(Datetime1, DateTime1) /C# newbie

  • Thread starter Thread starter genc ymeri
  • Start date Start date
G

genc ymeri

Hi I have DateTime1 and DateTime2.
How can I tell what is the difference in millisecons between them ?

Thank You.
 
System.Timespa

----- genc ymeri wrote: ----

Hi I have DateTime1 and DateTime2
How can I tell what is the difference in millisecons between them

Thank You
 
I had trouble using that command. "compile error "denote class".....not in
that context,,,,,"


Any sample how to use it please ?

Thanks a lot !
 
genc ymeri said:
I had trouble using that command. "compile error "denote class".....not in
that context,,,,,"


Any sample how to use it please ?

Thanks a lot !

Subtracting one DateTime value from another will return a TimeSpan
value. You can use the TimeSpan value to determine the total milliseconds in
the interval:

DateTime dateFirst = new DateTime(2004,3,4);
DateTime dateSecond = DateTime.Now;
TimeSpan dateDifference = dateSecond - dateFirst;

Console.WriteLine("The difference between {0} and {1} is {2}ms",
dateFirst,
dateSecond,
dateDifference.TotalMilliseconds);

Regards,
Dan
 
genc ymeri said:
Hi I have DateTime1 and DateTime2.
How can I tell what is the difference in millisecons between them ?

You can get the TimeSpan just by doing:

TimeSpan diff = DateTime2-DateTime1;

After that, there are various properties of TimeSpan you can use,
including TotalMilliseconds.
 
Thanks a lot !

Jon Skeet said:
You can get the TimeSpan just by doing:

TimeSpan diff = DateTime2-DateTime1;

After that, there are various properties of TimeSpan you can use,
including TotalMilliseconds.
 
Back
Top