Cita de: ostrede en 14 Agosto 2013, 02:58 AM¿Se podría hacer?
Así lo hice yo:
EDITO: He extendido la función para obtener horas, minutos y segundos.
Código (vbnet) [Seleccionar]
#Region " Date Difference "
' Date Difference
'
' // By Elektro H@cker
'
' Examples :
'
' MsgBox(DateDifference(DateTime.Parse("01/03/2013"), DateTime.Parse("10/04/2013"))) ' Result: 1 Months, 1 Weeks, 2 Days, 0 Hours, 0 Minutes and 0 Seconds
' MsgBox(DateDifference(DateTime.Parse("01/01/2013 14:00:00"), DateTime.Parse("02/01/2013 15:00:30"))) ' Result: 0 Months, 0 Weeks, 1 Days, 1 Hours, 0 Minutes and 30 Seconds
Private Function DateDifference(ByVal Date1 As DateTime, ByVal Date2 As DateTime) As String
Dim MonthDiff As String, WeekDiff As String, _
DayDiff As String, HourDiff As String, _
MinuteDiff As String, SecondDiff As String
MonthDiff = Convert.ToString(DateDiff("M", Date1, Date2))
WeekDiff = Convert.ToString(DateDiff("d", Date1.AddMonths(DateDiff("M", Date1, Date2)), Date2) \ 7)
DayDiff = Convert.ToString(DateDiff("d", Date1.AddMonths(DateDiff("M", Date1, Date2)), Date2) - (WeekDiff * 7))
HourDiff = Convert.ToString(DateDiff("h", Date1.AddHours(DateDiff("h", Date1, Date2)), Date2) - (Date1.Hour - Date2.Hour))
MinuteDiff = Convert.ToString(DateDiff("n", Date1.AddMinutes(DateDiff("n", Date1, Date2)), Date2) - (Date1.Minute - Date2.Minute))
SecondDiff = Convert.ToString(DateDiff("s", Date1.AddSeconds(DateDiff("s", Date1, Date2)), Date2) - (Date1.Second - Date2.Second))
Return String.Format("{0} Months, {1} Weeks, {2} Days, {3} Hours, {4} Minutes and {5} Seconds", _
MonthDiff, WeekDiff, DayDiff, HourDiff, MinuteDiff, SecondDiff)
End Function
#End Region
PD: Mi función no cuenta el primer día restante porque me parece incorrecto, del 1 al 7 no hay 7 días de diferencia, hay 6, si quieres obtener el resultado que comentas pues símplemente añade un "+ 1" a la diferencia de días.
Saludos!