Days, hours, minutes, seconds between two dates
TimeSpan is the object you need:
TimeSpan span = (DateTime.Now - DateTime.Now);
String.Format("{0} days, {1} hours, {2} minutes, {3} seconds",
span.Days, span.Hours, span.Minutes, span.Seconds);
When you subtract one DateTime
from another, you get a TimeSpan
instance, which exposes those values.
TimeSpan diff = DateTime.Now - DateTime.Today;
string formatted = string.Format(
CultureInfo.CurrentCulture,
"{0} days, {1} hours, {2} minutes, {3} seconds",
diff.Days,
diff.Hours,
diff.Minutes,
diff.Seconds);