Geeks With Blogs


Microsoft MVP


Moderator at CodeASP.NET

Quiz Master

free counters
Free counters
Added on January 19,2012

Follow Me @vmsdurano

A bit About Me

The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.

Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"
Here's an example on how to get the date difference between two given dates using TimeSpan.


protected void Page_Load(object sender, EventArgs e)
DateTime dFrom;
DateTime dTo;
string sDateFrom = "9/9/2007";
string sDateTo = "1/10/2008";
if (DateTime.TryParse(sDateFrom, out dFrom) && DateTime.TryParse(sDateTo, out dTo))
TimeSpan TS = dTo - dFrom;
int daysDiff = TS.Days;


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim dFrom As DateTime
Dim dTo As DateTime
Dim sDateFrom As String = "9/9/2007"
Dim sDateTo As String = "1/10/2008"
If DateTime.TryParse(sDateFrom, dFrom) AndAlso DateTime.TryParse(sDateTo, dTo) Then
Dim TS As TimeSpan = dTo - dFrom
Dim daysDiff As Integer = TS.Days
End If
End Sub


Technorati Tags: ,
Posted on Thursday, September 11, 2008 10:43 AM C# | Back to top

Comments on this post: Get the days difference between two Dates

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: