Please visit my new Web Site https://coderstechzone.com
In case of date time calculation from front end we need to find out the days difference between two given dates by user. Dates may come from dtpicker or from calendar control whatever we will use asp.net built in subtract method to identified the number of days or date difference between two dates. In this article i will show you to identify datediff between two dates in both C# and Vb.Net front end Language.
C# Code:
protected void Page_Load(object sender, EventArgs e) { DateTime dTFrom; DateTime dTo; string sFrom = "April 30, 2010"; string sTo = "May 08, 2010"; if (DateTime.TryParse(sFrom, out dTFrom) && DateTime.TryParse(sTo, out dTo)) { TimeSpan TS = dTo.Subtract(dTFrom); int days_Diff = TS.Days; Response.Write("Day diference between two dates: "+days_Diff.ToString()); } }VB.Net Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim dTFrom As DateTime Dim dTo As DateTime Dim sFrom As String = "April 30, 2010" Dim sTo As String = "May 08, 2010" If DateTime.TryParse(sFrom, dTFrom) AndAlso DateTime.TryParse(sTo, dTo) Then Dim TS As TimeSpan = dTo.Subtract(dTFrom) Dim days_Diff As Integer = TS.Days Response.Write(days_Diff.ToString()) End If End Sub
Hope now you can generate the date difference between two dates from a given date range.
0 comments:
I WOULD BE DELIGHTED TO HEAR FROM YOU