Example. In this program, we get two DateTimes. Then we get the difference as a TimeSpan instance. Next, we convert that TimeSpan into a long Ticks.
Finally We convert that long Ticks back into a TimeSpan, showing that you can round-trip longs and TimeSpans.
static void Main()
// Difference between today and yesterday.
DateTime yesterday = DateTime.Now.Subtract(TimeSpan.FromDays(1));
DateTime now = DateTime.Now;
TimeSpan diff = now.Subtract(yesterday);
// TimeSpan can be represented as a long [ticks].long ticks = diff.Ticks;
// You can convert a long [ticks] back into TimeSpan.
TimeSpan ts = TimeSpan.FromTicks(ticks);
// Note: long and TimeSpan are the same number of bytes .
Byte count. In the unsafe context, the program shows that a long is 8 bytes and a TimeSpan is also 8 bytes. Therefore, it is logical for one to fit in the other.