Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

ASP.NET: Calculate the difference between two dates

From Wiki

Jump to: navigation, search


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

  1. Dim d1 As Date = CDate("2007-12-01")
  2. Dim d2 As Date = CDate("2007-12-11")
  3. Dim t As New TimeSpan
  4. t = d2.Subtract(d1)  
  5.  
  6. Response.Write("Days: " & t.Days & "<br>")  
  7. Response.Write("Hours: " & t.Hours & "<br>")  
  8. Response.Write("Minutes: " & t.Minutes & "<br>")  
  9. Response.Write("Seconds: " & t.Seconds & "<br>")  
  10. Response.Write("Total Days: " & t.TotalDays & "<br>")  
  11. Response.Write("Total Hours: " & t.TotalHours & "<br>")  
  12. Response.Write("Total Minutes: " & t.TotalMinutes & "<br>")  
  13. Response.Write("Total Seconds: " & t.TotalSeconds & "<br>")


This Hack is part of the ASP.NET Hacks collection

450 Rating: 4.5/5 (2 votes cast)