Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

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: 3.7/5 (27 votes cast)