String convert to date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • help1267
    New Member
    • Aug 2006
    • 10

    #1

    String convert to date

    Hi,
    I'm working on an assignment that requires I loop through a list box with time strings (ex: 1:38 PM, 1:40 PM etc.)

    I need a time to compare the current time and the time in the list box and if the current time is greater I have a message box appearing.

    I can't get the message box to appear after the timer increments (my timer is anabled at 60000 interval).

    --This is the code structure I have so far but it's not working.

    I need the If statement to compare the current time and the times in the list box IN **Short Time format**. Any suggestions?

    For i = lstTime.Items.C ount - 1 To 0 Step 1

    If CDate(Now.Date. ToShortTimeStri ng) > Convert.ToDateT ime(lstTime.Ite ms(i)) Then
    MessageBox.Show ("Time has elapsed")
    End If
    Next
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    You can use the DateDiff() function

    DateDiff("s", Date1, Date2)

    This function returns 0 if both times are equal
    A positive integer if Date2 is later than Date1 in seconds
    A negative integer if Date2 is earlier than Date1 in seconds

    Comment

    Working...