Asp.net: Calculate total number of days between 2 dates

In this article I am going to explain how to calculate total number of days between two dates in asp.net.


Implementation: 
C# Code:
protected void Page_Load(object sender, EventArgs e)
    {
        DateTime date1 = new DateTime(2016,08,01);
        DateTime date2 = new DateTime(2016, 09, 13);
        string totaldays = (date2 - date1).TotalDays.ToString();
        Response.Write("Total days are :" + totaldays);
    }

VB.Net Code:
  Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim date1 As New DateTime(2016, 8, 1)
        Dim date2 As New DateTime(2016, 9, 13)
        Dim [totaldays] As String = (date2 - date1).TotalDays.ToString()
        Response.Write(Convert.ToString("Total days are :") & [totaldays])
    End Sub




Post a Comment

0 Comments