Something like this:
' A Start date an end Date to test with
Dim StartingDate As DateTime = DateTime.Now
Dim TargetEndDate As DateTime = DateTime.Now.AddYears(1).AddDays(5).AddMinutes(45)
' Get the difference between the two dates, and Create a new Date containing just the total days
Dim DifferenceBetweenDates As TimeSpan = TargetEndDate.Subtract(StartingDate)
Dim DiffFromSystemDate As New DateTime(0, 0, DifferenceBetweenDates.TotalDays)
' Get the number of years, months and days left
Dim NumberOfYears As Integer = DiffFromSystemDate.Year - 1
Dim NumberOfMonths As Integer = DiffFromSystemDate.Month - 1
Dim NumberOfDays As Integer = StartingDate.Day - DateTime.DaysInMonth(StartingDate.Year, StartingDate.Month)
' Build up the result string
Dim Result As String = String.Format("{0} YEAR, {1} MONTHS, {3} DAYS LEFT", NumberOfYears, NumberOfMonths, NumberOfDays)
- I haven't compiled it yet
- It doesn't fully work (leap years, and days of the year)
Please see JonSkeets post in the duplicate for a better way of doing this