ASP.NET: Calculate the difference between two dates
From Wiki
Summary: An example of how you can use the TimeSpan class to measure the difference between two dates.
Need help with ASP.NET? Come and ask a question in our ASP.NET Forum
- Dim d1 As Date = CDate("2007-12-01")
- Dim d2 As Date = CDate("2007-12-11")
- Dim t As New TimeSpan
- t = d2.Subtract(d1)
- Response.Write("Days: " & t.Days & "<br>")
- Response.Write("Hours: " & t.Hours & "<br>")
- Response.Write("Minutes: " & t.Minutes & "<br>")
- Response.Write("Seconds: " & t.Seconds & "<br>")
- Response.Write("Total Days: " & t.TotalDays & "<br>")
- Response.Write("Total Hours: " & t.TotalHours & "<br>")
- Response.Write("Total Minutes: " & t.TotalMinutes & "<br>")
- Response.Write("Total Seconds: " & t.TotalSeconds & "<br>")
This Hack is part of the ASP.NET Hacks collection


