How to Calculate Years & Months & Days ?

loyal

Centurion
Joined
Jul 29, 2003
Messages
102
hi all

I am trying to calculate Date.Now from start Time

by using DateDiff ... here's the code

Code:
Try
      Dim d1 As DateTime = CDate(DTPStartDate.Text)
      Dim WD As Long = _
      DateDiff("yyyymd", d1, Date.Now)
            
       txtTotalDays.Text = WD

     Catch ex As Exception
     MessageBox.Show(ex.Message)
        End Try


I want the output like 3,5,12

means 3 years , 5 months , 12 days

I used what ever I can to format the Interval with no result.

how can I get this, is it by DateDiff ?

any help would be appreciated
 
You should look at the TimeSpan class, which returns the difference in the standard DateTime format.
 
DateDiff just return you total days, you can divide it to get the ? years, ? months and ? days if you want...

DateDiff("d", d1, Date.Now)
 
Back
Top