How To work with TimeSpan Class

Platform: ASP.NET| Category: Basic

VB.NET


Dim adate As DateTime = DateTime.Parse('06/24/2003')
Dim bdate As DateTime = DateTime.Parse('06/28/2003')
Dim ts As New TimeSpan(bdate.Ticks - adate.Ticks)
Response.Write(ts.TotalDays & '<br>')
Response.Write(ts.TotalHours & ':' & ts.TotalMinutes & ':' & ts.TotalSeconds & ':' & ts.TotalMilliseconds)

C#


DateTime adate    = DateTime.Parse('06/24/2003');
DateTime bdate    = DateTime.Parse('06/28/2003');
TimeSpan ts = new TimeSpan (bdate.Ticks - adate.Ticks);
Response.Write(ts.TotalDays.ToString () + '<br>');
Response.Write(ts.TotalHours.ToString() + ':' + ts.TotalMinutes.ToString() + ':' + ts.TotalSeconds.ToString() +  ':' + ts.TotalMilliseconds.ToString() );

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.