?
Solved

timeago... if function not working

Posted on 2011-04-20
6
Medium Priority
?
252 Views
Last Modified: 2012-05-11
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 

Open in new window



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 ??
0
Comment
Question by:runnerjp2005
  • 3
  • 3
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35431725
Bit more explanation plz.
0
 

Author Comment

by:runnerjp2005
ID: 35431791
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.Result3.Split("|")(2), DateAndTime.Now)
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 

Open in new window


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


0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35431810
It is because string comparison is not same as date comparison.

Try
If ts.TotalMinutes <= 59 Then
  ...
Else
   ...
End If
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:runnerjp2005
ID: 35431833
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
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 35431837
How will 108 be less than 59?
0
 

Author Closing Comment

by:runnerjp2005
ID: 35431852
school boy error... yes i see that makes sence!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question