Member_2_5230414
asked on
timeago... if function not working
Public Class timeago
Shared Function GetDifferenceDate(ByVal date2 As DateTime, ByVal date1 As DateTime) As String
If DateTime.Compare(date1, date2) >= 0 Then
Dim ts As TimeSpan = date1.Subtract(date2)
If String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) > "0 days 0 hours 59 minutes" Then
Return String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) & " ...0 days 0 hours 59 minutes"
ElseIf String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) > "0 days 23 hours 59 minutes" Then
Return "<b>Today</b> at " & date1.ToString("hh:mm tt")
End If
End If
Return date2
End Function
for some reason my result shows 0 days 3 hours 45 minutes ...0 days 0 hours 59 minutes
so even tho its been 3 hours ago for some reason it is still returnin the If String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) > "0 days 0 hours 59 minutes" Then
have i got something wrong in my code ??
Bit more explanation plz.
ASKER
Hey CodeCruiser,
Ok what im trying to do is get the time of the post and display a message saying either 59 > min ago or today or yesterday
to do this i use timeago.GetDifferenceDate( Res.Result 3.Split("| ")(2), DateAndTime.Now)
but for some reason it ONLY shows Return String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) & " ...0 days 0 hours 59 minutes" even through it has been 3 hours since the last post
Ok what im trying to do is get the time of the post and display a message saying either 59 > min ago or today or yesterday
to do this i use timeago.GetDifferenceDate(
Public Class timeago
Shared Function GetDifferenceDate(ByVal date2 As DateTime, ByVal date1 As DateTime) As String
If DateTime.Compare(date1, date2) >= 0 Then
Dim ts As TimeSpan = date1.Subtract(date2)
If String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) > "0 days 0 hours 59 minutes" Then
Return String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) & " ...0 days 0 hours 59 minutes"
ElseIf String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) > "0 days 23 hours 59 minutes" Then
Return "<b>Today</b> at " & date1.ToString("hh:mm tt")
End If
End If
Return date2
End Function
but for some reason it ONLY shows Return String.Format("{0} days {1} hours {2} minutes", ts.Days, ts.Hours, ts.Minutes) & " ...0 days 0 hours 59 minutes" even through it has been 3 hours since the last post
It is because string comparison is not same as date comparison.
Try
If ts.TotalMinutes <= 59 Then
...
Else
...
End If
Try
If ts.TotalMinutes <= 59 Then
...
Else
...
End If
ASKER
But if i do ts.TotalMinutes <= 59 then if its 1hr 48min it will still return it as ts.TotalMinutes is still less than 59
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
school boy error... yes i see that makes sence!