How to get the difference in days between two dates using 2.0 and

Posted on 2009-02-09
Last Modified: 2012-06-27

I would like to get the difference in days between two dates using 2.0 and

Thanks in advace.
Question by:dimensionav
    LVL 8

    Accepted Solution

    U mean the number of days betwween two specified days??
     Dim txtDate1 As Date = CType(Me.TextBox1.Text, Date) 
       Dim txtDate2 As Date = CType(Me.TextBox2.Text, Date) 
       Dim MyDifference As TimeSpan 
            MyDifference = txtDate2.Subtract(txtDate1) ' find the number of days apart 
            MessageBox.Show(MyDifference.Days) ' Display to the user

    Open in new window

    LVL 8

    Expert Comment

    In C# you could do something lie this"
    DateTime startTime = DateTime.Now;
     DateTime endTime = DateTime.Now.AddSeconds( 75 );
     TimeSpan span = endTime.Subtract ( startTime );
     Console.WriteLine( "Time Difference (seconds): " + span.Seconds );
     Console.WriteLine( "Time Difference (minutes): " + span.Minutes );
     Console.WriteLine( "Time Difference (hours): " + span.Hours );
     Console.WriteLine( "Time Difference (days): " + span.Days );

    Open in new window


    Author Closing Comment

    It worked pretty well, Thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now