title: VB 2010: How to calculate a date difference?
body: <p>I'd like do make a program which returns you how old you are, in years, months, weeks and days. But I didn't get it to compare different times. </p>
  
  <p>Input is a string which looks like 01.01.2011 (dd.mm.yyyy).</p>
  
  <p>Please, can somebody help?</p>
  
  <p>Thanks very much!</p>
  
  <p>EDIT:</p>
  
  <p>My code so far is this:</p>
  
  <pre><code>Try
          dim date1 as string = '01.01.2011'
          ' Today
          Dim date2 As Date
          date2 = Date.Now
          ' number of seconds since date1
          Dim seconds As Long
          seconds = DateDiff("s", date1, date2)
          lbl_seconds.Text = seconds.ToString &amp; " Seconds"
          ' Number of minutes since date1
          Dim Minutes As Long
          Minutes = DateDiff("n", date1, date2)
          lbl_minutes.Text = Minutes.ToString &amp; " Minutes"
          ' Number of hours since date1
          Dim hours As Long
          hours = DateDiff("h", date1, date2)
          lbl_hours.Text = hours.ToString &amp; " Hours"
          ' Days
          Dim days As Long
          days = DateDiff("d", date1, date2)
          lbl_days.Text = days.ToString &amp; " Days"
          ' weeks
          Dim weeks As Long
          weeks = DateDiff("ww", date1, date2)
          lbl_weeks.Text = weeks.ToString &amp; " Weeks"
          'months
          Dim months As Long
          months = DateDiff("m", date1, date2)
          lbl_months.Text = months.ToString &amp; " Months"
          ' Years
          Dim years As Long
          years = DateDiff("yyyy", date1, date2)
          lbl_years.Text = years.ToString &amp; " Years"
  
  
      Catch ex As Exception
          date1 = "01.01.2011"
          MsgBox("not a valid date given!")
      End Try
  </code></pre>