Question:

Time elapsed between two dates in VB.Net?

by  |  earlier

0 LIKES UnLike

Can anyone guide me as to how to display the number of years and months that have past, on a text box I placed on a form from the date that the user picked on a date picker control from the same form.

Thanks so much!

 Tags:

   Report

3 ANSWERS


  1. You use the DateDiff() function  


  2. Check this link, with a few minor modifications it'll answer your question.

    Checa esta liga, modificandole un poquito podras usarla para que te regrese lo que pides, Espero sea de ayuda, Saludos!

    http://www.planet-source-code.com/vb/scr...


  3. I do not have much experience with VB.net. But, you might see if this gets you close enough to work it out.  This should give you the info in a message box.  

    Private Sub DetermineNumberofYearsMonths()

              Dim dtStartDate As Date

              dtStartDate = "Date from User's input"

              Dim tsTimeSpan As TimeSpan

              Dim iNumberOfYears As Integer

              Dim iNumberOfMonths As Integer

              tsTimeSpan = Now.Subtract(dtStartDate)

              iNumberOfYears = tsTimeSpan.Years

              iNumberOfMonths = tsTimeSpan.Months

    strMsgText = "The time elapsed since " _

    & dtStartDate. _

    ToShortDateString() _

    & " is: " & iNumberOfYears.ToString() _

    & " years and " & iNumberOfMonths.ToString() & " months."

    MsgBox (strMsgText)

    End Sub

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.